django:我如何实际覆盖管理员网站模板 [英] django: how do I actually override admin site template

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

问题描述

我知道这是被问及回答了好几次,但是我基本上都是在堆栈溢出的时候完成了所有的工作,但仍然无法让它工作。现在我只是想改变管理员网站的标题。我有以下内容:

 #base_site.html 
{%extendsadmin / base_site.html%}

{%block title%} {{title}} | {{site_title | default:_('NEW TITLE')}} {%endblock%}

{%block branding%}
< h1 id =site-name> < a href ={%url'admin:index'%}> {{site_header | default:_('NEW TITLE')}}< / a>< / h1>
{%endblock%}

{%block nav-global%} {%endblock%}

我试图把它放在


my_site / templates / admin / base_site.html,



my_site / templates / admin / my_app / base_site.html和



my_site / my_app / templates / admin / base_site


但这些都不行。

  settings.py:
TEMPLATES = [
{
'BACKEND':'django.template.backends.django.DjangoTemplates',
'DIRS' [os.path.join(BASE_DIR,'templates')],
'OPTIONS':{
'context_processors':[
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages'
],
'loaders':[
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
},
},
]

也尝试只是直接更改django\contrib\admin\templates\admin\base_site.html但仍然没有发生任何事情。



我现在真的很沮丧,绝对可以使用一些帮助,谢谢



更新:
其实我发现本地模板确实有效果。



像这里,最上面的白色条显示#base_site.html!!@#是我把my_site / templates / admin / base_site.html作为评论的机会。所以它有点工作,但我仍然不明白为什么我不能更改网站标题。

解决方案

使用my_site / my_app / templates / admin / base_site.html


将您的应用程序放在您定义此模板之前
'django.contrib.admin ',INSTALLED_APPS


链接


I know this is asked and answered several times but I basically went over all the post on stack overflow and still couldn't get this to work. Right now I am just trying simply change the admin site title. I have the following:

#base_site.html
{% extends "admin/base_site.html" %}

{% block title %}{{ title }} | {{ site_title|default:_('NEW TITLE') }}{% endblock %}

{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('NEW TITLE') }}</a></h1>
{% endblock %}

{% block nav-global %}{% endblock %}

And I tried to put this in

my_site/templates/admin/base_site.html,

my_site/templates/admin/my_app/base_site.html, and

my_site/my_app/templates/admin/base_site.html,

but none of these work.

settings.py:
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
            'loaders': [
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
            ],
        },
    },
]

I also tried just directly changing django\contrib\admin\templates\admin\base_site.html but still nothing happens.

I am really frustrated now and definitely could use some help, thanks

Updates: Actually I found out that the local template does have effect.

Like here, the topmost white bar displays "#base_site.html!!@#" which is what I put in my_site/templates/admin/base_site.html as a comment by chance. So it kinda working, but I still don't understand why I can't change the site title.

解决方案

use my_site/my_app/templates/admin/base_site.html

put your app where you define this template before 'django.contrib.admin', in INSTALLED_APPS

link

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

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