【发布时间】:2015-12-10 02:20:12
【问题描述】:
我的 Django 模板位置被列为:
python\Lib\site-packages\django\contrib\auth\templates
在我看来,我有:
return render_to_response('hello.html', {'name': name})
当我将hello.html 放在这个位置时,它就可以工作了
python\Lib\site-packages\django\contrib\auth\templates
虽然我将模板位置保留为
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), 'templates'),
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
NewProject
-NewProject
settings.py
-signups
view.py
def hello(request):
name='vijay'
return render_to_response('hello.html',{'name':name})
templates
hello.html
【问题讨论】:
-
与其说不起作用,不如好好看看堆栈跟踪,看看它说了什么,如果您需要帮助,请将其添加到问题中。
-
@user1844634 django 版本是什么?
-
只需打印 os.path.join(os.path.dirname(file), 'templates'),它在 settings.py 文件中并在您的错误页面上结帐django 尝试在您的项目中找到您的模板文件夹以获取更多信息:stackoverflow.com/questions/3038459/django-template-path