django覆盖管理模板 [英] django override admin template

查看:88
本文介绍了django覆盖管理模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注Django教程的第2部分。我试图覆盖一个管理模板( base_site.html

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

我将文件从 django / contrib / admin / templates to mytemplates / admin / base_site.html

我还更新了settings.py:

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

我尝试将mytemplates文件夹放在项目文件夹的根目录以及没有运气的mysite文件夹中。任何指针都会很棒!

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!

推荐答案

以前的用户回复 - 这个工作:

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. mytemplates dir与 manage.py 文件

project
-app1
-app2
-mytemplates
    -admin
        -base_site.html
-manage.py


  • 将TEMPLATE_DIRS更改为:

  • Change the TEMPLATE_DIRS to:

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


  • 确保模板加载器的顺序是:

  • Make sure the order of the template loader is:

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


  • 这篇关于django覆盖管理模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆