Django 找不到 HTML 文件
我有一个 html 文件('search.html'),上面有一个表单。我将其保存到 ~/Django/Templates 只是为了争论。 Django 书上说我把它保存在哪里并不重要,因为框架会找到它。不管怎样,我在views.py文件中设置了一个函数来渲染这个文件。就是这样:
from django.http import HttpResponse
from django.shortcuts import render_to_response
def search(request):
return render_to_response('search.html')
我也在 urls.py 文件中调用了这个函数:
urlpatterns = patterns('',
(r'^$', index),
(r'^search/$', search),
但是,每当我访问 URL 中包含 ~/search 的页面时,我都会得到以下信息:
模板不存在于/search/
有什么问题?
I have a html file ('search.html') with a form on it. I have saved it to ~/Django/Templates just for the sake of argument. The Django book said it doesn't matter where I save it, because the framework will find it. Anyway, I have set up a function in the views.py file to render this file. Here it is:
from django.http import HttpResponse
from django.shortcuts import render_to_response
def search(request):
return render_to_response('search.html')
I have this function called in the urls.py file as well:
urlpatterns = patterns('',
(r'^
However, whenever I go to visit the page with the ~/search in the URL, I get the following:
TemplateDoesNotExist at /search/
What's the problem?
, index),
(r'^search/
However, whenever I go to visit the page with the ~/search in the URL, I get the following:
TemplateDoesNotExist at /search/
What's the problem?
, search),
However, whenever I go to visit the page with the ~/search in the URL, I get the following:
TemplateDoesNotExist at /search/
What's the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的 settings.py 文件中有一行...
您要确保包含模板的目录位于该元组中。
In your settings.py file there is a line...
You want to make sure the directory containing the template is in that tuple.