Django: Overrideing base_site.html

2019-02-25 13:04发布

问题:

Folks, I tried following steps in the Django Tutorial for customizing the admin template. I followed the steps to the letter, creating a directory structure as follows:

 - myproject/
   - myproject/
     - templates/
       - admin/
         - base_site.html
   - myapp1/
   - manage.py

I edited base_site.html to change text "Django site admin" to "My site admin".

I edited myproject/settings.py to add:

TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]

Upon running this, my changes to base_site.html did not take effect.

I then followed the advise on this post and created the following directory structure:

 - myproject/
   - myproject/
   - templates/
     - admin/
       - base_site.html
   - myapp1/
   - manage.py

And added the following to my settings.py file:

TEMPLATE_DIRS = (os.path.join(BASE_DIR,'..', 'mytemplates'),)
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
)

I am still greeted by "Django administration" when I visit the admin page. What am I doing wrong?

回答1:

BASE_DIR refers to, well, the base dir, So you should use the original value of TEMPLATE_DIRS with the new layout.