[英]Django 1.7 Configure App Directory Templates
I am trying to load app specific templates in my Django 1.7 project. 我正在尝试在Django 1.7项目中加载特定于应用程序的模板。 Here is my directory structure:
这是我的目录结构:
ProjectX
- manage.py
- ProjectX
- settings.py
- urls.py
- App1
- urls.py
- Templates
- App1
- something1.html
- App2
- urls.py
- Templates
- App2
- something2.html
Now i have configured the following into my ProjectX/ProjectX/settings.py: 现在,我在ProjectX / ProjectX / settings.py中配置了以下内容:
TEMPLATE_PATH = os.path.join(BASE_DIR, 'templates')
TEMPLATE_DIRS = (
TEMPLATE_PATH,
)
When I do: 当我做:
render_to_response("app1/somthing1.html",.....)
I go to the PATH ProjectX/Templates/App1/something1.html 我转到PATH ProjectX / Templates / App1 / something1.html
Whereas I would want something like ProjectX/App1/Templates/App1/something1.html 而我想要类似ProjectX / App1 / Templates / App1 / something1.html的文件
Any idea how I can make this happen without changing the render_To_response statement? 我知道如何在不更改render_To_response语句的情况下实现这一目标吗?
You should remove the TEMPLATE_PATH
in your settings and change TEMPLATE_DIRS
to 您应该在设置中删除
TEMPLATE_PATH
并将TEMPLATE_DIRS
更改为
TEMPLATE_DIRS = (
os.path.join(PROJECT_DIR, 'templates').replace('\\', '/'),
os.path.join(BASE_DIR, 'App1/templates').replace('\\', '/'),
os.path.join(BASE_DIR, 'App2/templates').replace('\\', '/')
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.