Welcome to OGeek Q&A 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 Reply

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',
    
    )
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...