惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
博客园 - 【当耐特】
Cyberwarzone
Cyberwarzone
B
Blog
U
Unit 42
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
WordPress大学
WordPress大学
美团技术团队
Hugging Face - Blog
Hugging Face - Blog
大猫的无限游戏
大猫的无限游戏
博客园 - 聂微东
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园 - 叶小钗
F
Full Disclosure
Microsoft Azure Blog
Microsoft Azure Blog
Recorded Future
Recorded Future
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
云风的 BLOG
云风的 BLOG
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
阮一峰的网络日志
阮一峰的网络日志
C
CERT Recently Published Vulnerability Notes
F
Fortinet All Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
C
Cisco Blogs
The Hacker News
The Hacker News
Know Your Adversary
Know Your Adversary
S
Securelist
S
Schneier on Security
P
Privacy International News Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
AWS News Blog
AWS News Blog
J
Java Code Geeks
T
The Exploit Database - CXSecurity.com
The Last Watchdog
The Last Watchdog
S
Secure Thoughts
C
Cybersecurity and Infrastructure Security Agency CISA
H
Heimdal Security Blog
博客园 - Franky
P
Palo Alto Networks Blog
PCI Perspectives
PCI Perspectives
T
Tailwind CSS Blog
IT之家
IT之家
Engineering at Meta
Engineering at Meta
Latest news
Latest news
P
Proofpoint News Feed
量子位
Apple Machine Learning Research
Apple Machine Learning Research
K
Kaspersky official blog

博客园 - 飞天名猪

新手上路,django学习笔记(1) 环境部署 Windows7系统命令总结 VC 编程ANSI环境下读写Unicode文件(转载) ICE3.1.1 开发中遇到的问题(四) 发布9个腾讯微博的邀请码 [转载]vc6转2008的一些实践经验 - 飞天名猪 - 博客园 IcePatch2+IceGrid部署的解决方案 ICE 开发中遇到的问题(三) Ice开发中遇到的问题(二) ICE开发中遇到的问题 (一) - 飞天名猪 - 博客园 使用ICE遇到的编译问题 dbf文件结构 判断操作系统的类型 浏览器插件-- Browser Helper Object(BHO) 四 浏览器插件-- Browser Helper Object(BHO) 三 浏览器插件-- Browser Helper Object(BHO) 二 浏览器插件-- Browser Helper Object(BHO) 一 window程序自启动的几种方法(四) windows程序自启动的几种方法(三)系统配置文件
django 定制管理页面外观 模板文件不生效的解决方法
飞天名猪 · 2017-03-26 · via 博客园 - 飞天名猪

问题描述:大概过程跟下面描述的一样,简单来说就是照着例子学习的时候定制管理页面外观,按照文档要求拷贝了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!