问题描述:大概过程跟下面描述的一样,简单来说就是照着例子学习的时候定制管理页面外观,按照文档要求拷贝了base_site.html文件到templates目录下,并且按照要求修改了settings.py文件之后,模板文件死活不生效的问题。

百度了很久,看到不少遇到这个问题的帖子,但是都没有明确是怎么解决的。

解决方法: 文档要求在settings.py后面添加这么一段

mysite/settings.py:

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

但是在settings.py文件中实际上已经定义了TEMPLATE_DIRS了,在后面再加一段这个设置属于重定义,正确的写法应该是找到前面的TEMPLATE=

在后面的DIR属性中增加上面的代码就可以了,不需要单独在settings.py后面加这段完整代码。

代码示例:

作为一个django新手,例子程序也不写清楚一点,能想到重复定义,并去试了试把TEMPLATE_DIRS 的内容直接改到TEMPLATE里面去也是服了我自己了。不管怎么样,终于解决了一个问题。

下面是这个问题的详细描述,在网上百度解决方案时找到的,跟我的情况是一样的。

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!

最新文章

  1. Hibernate的实体类为什么要实现Serializable序列化接口?
  2. 一道 google曾出过的笔试题:编程实现对数学一元多项式的相加和相乘操作(1)
  3. Paxos算法之旅(四)zookeeper代码解析--转载
  4. CentOS管理
  5. hdu 1181 变形课(dfs)
  6. python进阶学习笔记(二)
  7. Python 字典和集合基于哈希表实现
  8. 使用springMVC时的web.xml配置文件
  9. VS2008生成解决方案卡顿、龟速
  10. 文献导读 | Single-Cell Sequencing of iPSC-Dopamine Neurons Reconstructs Disease Progression and Identifies HDAC4 as a Regulator of Parkinson Cell Phenotypes
  11. Docker构建FastDFS镜像
  12. 【netcore基础】ConcurrentDictionary 使用字符串作为key给代码加锁且使用EF事物防止并发调用数据混乱的问题
  13. java的四大特性
  14. 05-使用jQuery操作input的value值
  15. mysql 用户表结构设计,第三方登录
  16. SignalR WebSocket Error during WebSocket handshake: net::ERR_CONNECTION_RESET
  17. os模块-subprocess 模块- configpaser 模块
  18. 合并两个dt
  19. linux 信号处理 四 (sigaction参数说明)
  20. Redis(一):概述

热门文章

  1. ehcache配置:使用Spring+SpringMVC+Mybatis或者有shiro
  2. Keras Sequential顺序模型
  3. 2_bootstrap的环境搭建
  4. 好记性不如烂笔头-linux学习笔记2kickstart自动化安装和cacti
  5. Selenium Webdriver——Table类封装
  6. web.xml中配置spring.xml的三种方式
  7. Frequently Used Shell Commands
  8. Vue SPA应用中使用Layer的iframe 弹出层,并且传值
  9. jQuery的过滤器总结
  10. 一些json在js和c++ jsoncpp的操作