Django 找不到 HTML 文件

发布于 2024-08-21 09:24:31 字数 566 浏览 4 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼趣 2024-08-28 09:24:31

在您的 settings.py 文件中有一行...

TEMPLATE_DIRS = (...)

您要确保包含模板的目录位于该元组中。

In your settings.py file there is a line...

TEMPLATE_DIRS = (...)

You want to make sure the directory containing the template is in that tuple.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文