问题描述:大概过程跟下面描述的同样,简单来讲就是照着例子学习的时候定制管理页面外观,按照文档要求拷贝了base_site.html文件到templates目录下,而且按照要求修改了settings.py文件以后,模板文件死活不生效的问题。html
百度了好久,看到很多遇到这个问题的帖子,可是都没有明确是怎么解决的。python
解决方法: 文档要求在settings.py后面添加这么一段sql
mysite/settings.py:django
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
可是在settings.py文件中实际上已经定义了TEMPLATE_DIRS了,在后面再加一段这个设置属于重定义,正确的写法应该是找到前面的TEMPLATE=学习
在后面的DIR属性中增长上面的代码就能够了,不须要单独在settings.py后面加这段完整代码。url
代码示例: code
做为一个django新手,例子程序也不写清楚一点,能想到重复定义,并去试了试把TEMPLATE_DIRS 的内容直接改到TEMPLATE里面去也是服了我本身了。无论怎么样,终于解决了一个问题。server
下面是这个问题的详细描述,在网上百度解决方案时找到的,跟个人状况是同样的。sqlite
I am working through https://docs.djangoproject.com/en/1.7/intro/tutorial02
so far all went fine - but now *templates changes just don't work.*
I think there must be a flaw in that tutorial, something missing,
or something different in django 1.7.1 ?
https://docs.djangoproject.com/en/1.7/intro/tutorial02/#customize-the-admin-look-and-feel
my versions:
python -c "import django; print(django.get_version())"
1.7.1
python --version
Python 2.7.3
*SYMPTOM:*
my changes in
mysite/templates/admin/base_site.html
are simply ignored.
These are my files:
mysite# tree
.
├── db.sqlite3
├── manage.py
├── mysite
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── polls
│ ├── admin.py
│ ├── __init__.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ └── __init__.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
└── templates
└── admin
└── base_site.html
mysite/settings.py:
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
*Whatever I do, the page*
*http://myserver:8000/admin/polls/question/
*
*still keeps the old title 'Django administration'*
I want to understand how templates work, because I need them for my real
project.
Thanks a lot!htm