如何给模板目录的路径 [英] How to give the path for template directory
本文介绍了如何给模板目录的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的模板无法识别,我收到以下错误。
My templates are not recognized and I'm getting the following error.
os.path.dirname(__file__)+'\\template' NameError: name 'os' is not defined
我有在设置中使用的是:
The code which I have used in settings is:
os.path.dirname(__file__)+'\\template'
我现在应该怎么做。
推荐答案
os模块丢失您没有导入使用它
os module is missing You have used it without importing
将其添加到您的settings.py
Add this in your settings.py
import os
TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'templates'),)
并将所有模板放在项目中的模板文件夹下
and place all your templates under templates folder in your project
,您可以使用Windows中的绝对路径(/ home / your_project /../模板)
但这不是很好的做法
and you can use absolute paths like linux(/home/your_project/../templates) in windows ("C:/your_project/../templates") but it is not good practice
这篇关于如何给模板目录的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文