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

推荐订阅源

量子位
T
The Blog of Author Tim Ferriss
U
Unit 42
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
Vercel News
Vercel News
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
D
DataBreaches.Net
The GitHub Blog
The GitHub Blog
大猫的无限游戏
大猫的无限游戏
C
Check Point Blog
Blog — PlanetScale
Blog — PlanetScale
I
InfoQ
Y
Y Combinator Blog
F
Full Disclosure
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
Google Developers Blog
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
博客园 - 叶小钗
S
SegmentFault 最新的问题
腾讯CDC
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
Visual Studio Blog
Apple Machine Learning Research
Apple Machine Learning Research
人人都是产品经理
人人都是产品经理
Recent Commits to openclaw:main
Recent Commits to openclaw:main
The Register - Security
The Register - Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Azure Blog
Microsoft Azure Blog
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
F
Fortinet All Blogs
C
CXSECURITY Database RSS Feed - CXSecurity.com
Hugging Face - Blog
Hugging Face - Blog
T
Threatpost
GbyAI
GbyAI
G
GRAHAM CLULEY
L
Lohrmann on Cybersecurity
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
L
LangChain Blog
T
Tenable Blog
C
Cisco Blogs
T
Threat Research - Cisco Blogs
Google Online Security Blog
Google Online Security 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!