django 在应用app下面template
来源:互联网 发布:开网络棋牌 编辑:程序博客网 时间:2024/06/06 00:46
今天做着玩的一个应用。使用django,按照惯例,创建项目后,又创建了一个app,考虑到每个app会有不同的布局,所以在每个app下面新建了一个templates,但是在应用的时候出现了问题。
在app下面新建了一个templates的文件夹,然后在这个下面又新建了一个app2的文件夹,在app2里面建了一个index.html 本来我想用他的。 按照惯例,引进各种需要的包以后,开始render
def text_base(request): return render(request, 'app2/index.html', {'data': 2})
但是出错了。总是说找不到模板。查看了一下堆栈:
TemplateDoesNotExist at /app2/index/下面Template-loader postmortem:Using loader django.template.loaders.app_directories.Loader:/usr/local/lib/python2.7/dist-packages/django/contrib/auth/templates/app2/index.html (File does not exist)
原来他是默认的在django的目录下找,于是乎我把django的template拷贝到我的site目录下,然后设置了一后,出现了新的提示:
TemplateDoesNotExist at /app2/index/Template-loader postmortemDjango tried loading these templates, in this order:Using loader django.template.loaders.filesystem.Loader:/layout/templates/app2/index.html (File does not exist)Using loader django.template.loaders.app_directories.Loader:/usr/local/lib/python2.7/dist-packages/django/contrib/auth/templates/app2/index.html (File does not exist)
原来django会在指定的templates下面找,如果找不到的话,再去默认的模板里面找。但是我的问题好像与模板无关。去查了查文档,原来是我们没有install app2 ,在setting.py 里面的INSTALLED_APPS 配置项下加上 ‘app2‘ ?问题就解决了。
我的理解是:django会根据安装的app去自己下面templates找,找不到,根据配置去自己设置的目录下找,如果再找不到就去django的templates目录下面找。
转载注明地址:http://www.chengxuyuans.com/Python/67367.html
0 0
- django 在应用app下面template
- django 在应用app下面template
- Django 1.6: 在template里访问session
- urllib unquote 在django template上面问题
- 在django template中设置临时变量
- Django template
- Django template
- django template
- Django Template
- Django Template
- django-apps下面有多个app以及增加搜索路径
- 在Django中自定义filter并在template中使用
- Django中在template中使用静态文件
- django template 基础(二)(在视图中使用模板)
- Django在windows以及mac下面的安装
- Django笔记-Template
- django template filter
- Django笔记-Template
- 【项目管理】之springMVC+spring+Mybatis环境搭建
- 设置MyEclipse或Eclipse 中 Jsp页面的默认编码
- Android Handler内存泄露分析
- cocos ide 调试lua 程序自动关闭问题的解决
- 使用retn指令调用API
- django 在应用app下面template
- tomcat启动,报问题:To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
- (1) 漂亮的日期控件
- java endsWith()和startsWith方法的解释
- js代码获取IP地址的三种方法,通过js取得客户端的IP地址。
- Ubuntu环境下的iptables的端口转发配置实例
- Android studio报module not specified的处理
- 使用自定义的RelateLayout实现列表布局
- CodeForces 25BPhone numbers(简单的字符串模拟题目)