自定义django管理模板不工作 [英] Custom django admin templates not working

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

问题描述

我一直在尝试为Django的管理页面获取自定义模板,但没有成功。我已经阅读了django文档和几个博客,将其解释为一个简单的步骤,我认为这是一个简单的步骤。



到目前为止,管理页面工作,但我自己重写的CSS或模板是不行的。我的设置如下

  / project_folder / 
manage.py
settings.py
urls.py
__init__.py
/ app /
views.py
models.py
__init__.py
/ templates /
/ admin /
base_site.html

在urls.py中我有

 (r'^ admin /',include(admin.site.urls)),
pre>

哪些工作,因为我无法登录等等。所以我假设/admin/base_site.html将覆盖默认的,但它没有做的事情。 / p>

任何人都知道这里发生了什么?我从Django教程/指南中跟随它,并且去了一些博客,看看他们是否有答案,但他们都说同样的话。



编辑1:
我的模板目录设置正确。

  TEMPLATE_DIRS =(
os.path.join(PROJECT_PATH,'templates /'),

这可以正常工作,因为我的网站其余部分工作与CSS的媒体目录等。唯一似乎不接受模板的是管理部分。

解决方案

我修正了,这是一个愚蠢的错误,但是我已经在玩这个过去2个小时了。我不得不在django.contrib.admin之前声明我的应用程序。否则不会接受。


I've been trying to get custom templates for the admin page for Django working but have been unsuccessful. I've read the django documentation and several blogs which explain it as being such an easy step, which I assumed it was.

As of right now the admin page works but my own rewrite of the CSS or templates is not working. My setup is as follows

/project_folder/
      manage.py
      settings.py
      urls.py
      __init__.py
      /app/
          views.py
          models.py
          __init__.py
          /templates/
                /admin/
                    base_site.html

In the urls.py I have

(r'^admin/', include(admin.site.urls)),

Which works since I cannot login etc. So I am assuming the /admin/base_site.html would overwrite the default one but it isn't doing a thing.

Anyone know what is going on here ? I followed it from the Django tutorials/guides and went onto some blogs to see if they had answers but they all said the same thing.

Edit 1: I do have my templates directory setup correctly.

TEMPLATE_DIRS = (
    os.path.join(PROJECT_PATH, 'templates/'),
)

This works correctly as I have the rest of my site working with a media directory for CSS etc. The only thing not seeming to 'accept' the templates is the admin section.

解决方案

Alright I fixed it, this was a stupid mistake but I was already playing with this for the past 2 hours. I had to declare my app before django.contrib.admin. It wouldn't accept it otherwise.

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

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