Can't change Django admin template

北城余情 提交于 2020-01-04 13:47:27

问题


just started an official Django tutorial and already ran into a problem, can't change page name in admin panel. I'm trying to replace a default Django administration with something custom in the base_site.html as suggested in the tutorial (a file which I copied from the django source directory into my app, tried to move it in/out polls directory etc.),
I have added in settings TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')], and in installed apps also 'polls', but nothing changes.

Any suggestions what I can do in order to make it work?

Thanks


回答1:


It will not work if you only change the value inside the parentheses like this

{{ site_header|default:_('Your custom name') }}

What you need to do is you must replace all of the above with your desired name like this.

{% extends "admin/base.html" %}

{% block title %}{{ title }} | YOUR CUSTOM NAME{% endblock %}

{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">YOUR CUSTOM NAME</a></h1>
{% endblock %}

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



回答2:


I created a templates folder at the root level of my Django Site.

base-folder 
--apps
--templates 
----admin 
------base_site.html

I edited base_site.html like I wanted, I just changed the name like you are trying to. Then I added this line into my settings.py

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

This worked for me. If you are seeing the admin site when you type /admin that means your url-config is set. Just make sure that your TEMPLATE_DIRS matches the directory of the admin template. You should have admin directory within the templates directory that contains all the necessary templates for the admin page.



来源:https://stackoverflow.com/questions/28787823/cant-change-django-admin-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!