問題描述:大概過程跟下面描述的同樣,簡單來講就是照着例子學習的時候定製管理頁面外觀,按照文檔要求拷貝了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/
<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