Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

django override admin template

I am following part 2 of the Django tutorial. I am trying to override an admin template (base_site.html)

I copied the file from the django/contrib/admin/templates to mytemplates/admin/base_site.html

I also updated settings.py:

#Base Directory
BASE_DIR = os.path.dirname(os.path.abspath(__file__))

#Template directories
TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'mytemplates'),)

I tried putting the mytemplates folder in the root of the project folder as well as in the mysite folder with no luck. Any pointers would be great!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

EDITED PREVIOUS USER RESPONSE -- THIS WORKS:

I think your relative path to the templates directory is wrong.

If you follow these steps it should work: (I tested it myself)

  1. Put the mytemplates dir side by side with the manage.py file

    project
    -app1
    -app2
    -mytemplates
        -admin
            -base_site.html
    -manage.py
    
  2. Change the TEMPLATE_DIRS to:

    TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'mytemplates'),)
    
  3. Make sure the order of the template loader is:

    TEMPLATE_LOADERS = (
    
        'django.template.loaders.filesystem.Loader',
        'django.template.loaders.app_directories.Loader',
    
    )
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...