Django1.7解决模板路径TEMPLATE_DIRS配置问题
2015-12-25 21:45
337 查看
跟着老师的视频学习Django框架,到了使用模板那里时,发现在自己的应用blog/下面创建的templates/怎么也不能成功加载,通过错误提示发现Django自动去blog/index下面去找模板。通过网上搜集了一些解决办法,就是在setting.py文件中添加TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), 'templates').replace('\\', '/'),
)
照着做了以后还是不行,提示和之前相同的错误,说明路径的配置并没有生效。
猛然想到,os.path.dirname(__file__)是settings.py的路径,那么,添加templates之后的路径是settings.py同一个目录下的templates,但是我的templates确是在../blog/templates/这里,吧TMPLATE_DIRS改为TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), '../blog/templates').replace('\\', '/'),
)
成功加载到了templates中的模板文件!
os.path.join(os.path.dirname(__file__), 'templates').replace('\\', '/'),
)
照着做了以后还是不行,提示和之前相同的错误,说明路径的配置并没有生效。
猛然想到,os.path.dirname(__file__)是settings.py的路径,那么,添加templates之后的路径是settings.py同一个目录下的templates,但是我的templates确是在../blog/templates/这里,吧TMPLATE_DIRS改为TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), '../blog/templates').replace('\\', '/'),
)
成功加载到了templates中的模板文件!
相关文章推荐
- Monogodb 分组操作
- idea + go插件开发
- Go 语言循环语句
- Go 语言条件语句
- go装饰模式,一个屌丝撸管的故事
- mongoose API
- Category类别
- go语言接口适配,适配器模式
- Google 新推出Background sync API
- Google 新推出Background sync API
- 如何快速地从mongo中提取数据到numpy以及pandas中去
- instance variables may not be placed in categories
- Can I change the order of items in category views?
- How to move items to another category
- How to use an FC category as Homepage / Frontpage
- Google分布式系统三驾马车: GFS,mapreduce,Bigtable
- mangos源码分析
- UVa 802 - Lead or Gold
- Go lang学习
- RockMongo安装使用笔记