Django (v) The first Django app creates a template that modifies the admin appearance

Source: Internet
Author: User

In the previous chapter, we completed the basic functions of admin, but the appearance of it is too ugly, then we will try to change it ~

If you want to change it, you'll use Django's templating system. Because admin is a Django-brought app, he uses a Django-brought template system.

First you need to create a template folder in the project, you can put it anywhere in the file, assuming the path is Mysite/templates Note: Here the MySite is the outermost folder. Modify settings.py:

Template_dirs = (    r'C:\mysite\templates',)

Then create a new admin folder under the Templates directory (this step is important!) )

Next, we'll find the Django/contrib/admin/templates/admin folder from the Django directory.

You can find the Django location by entering the following code in Python interactive mode:

Import sys>>> sys.path=sys.path[1]import  Djangoprint(Django.  __path__) ['c:\\python27\\lib\\site-packages\\django']

Then copy the django/contrib/admin/templates/admin/base_site.html file to your Mysite/templates/admin directory.

Open the base_site.html with the following contents:

{% extends "admin/base.html"%}{% load i18n%}{% block title%}{{title}} | {% trans ' Django site Admin '%} {% Endblock%} {% block branding%} <  ID= "Site-name">{% trans ' Django administration '%}</H1 > {% endblock%}{% block Nav-global%}{% endblock%}

This {% block title%},{{title}} is a template language that will automatically be converted to HTML when Django renders base_site.html. Now we don't have to delve into these template languages for the time being, as long as we know what they mean.

Note that you cannot modify his template directly under Django's own Admin folder, and you can only copy it in your own directory.

To change the login screen home page, as before, copy the admin/index.html into your own directory.

To edit the file, you will see a variable called App_list, which contains all of Django's installed apps.

Now that we know how to customize it, but this is not our main learning goal, let's put it aside for a while and continue with the following learning goals.

Django (v) The first Django app creates a template that modifies the admin appearance

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.