为什么 django 不加载我的视图

发布于 2024-10-04 02:42:04 字数 769 浏览 3 评论 0原文

当我尝试加载网站时,出现“找不到页面”错误。(127.0.0.1:8000/catalog/)

这是我的 urls.py

urlpatterns = patterns('',
(r'^catalog/$', 'preview.views.home'),
# Example:
# (r'^ecomstore/', include('ecomstore.foo.urls')),

# Uncomment the admin/doc line below to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
# (r'^admin/', include(admin.site.urls)),    
)

在包预览中,我的views.py

from django.shortcuts import render_to_response

# Create your views here.
def home(request):
    return render_to_response("index.html")

“index.html”位于文件夹 ecomstore/templates,变量 TEMPLATE_DIRS 设置为此目录。

奇怪的是我没有调试跟踪,但 DEBUG 变量设置为 true 有人知道出了什么问题吗?

I get an 'Page not found' error when i try to load the site.(127.0.0.1:8000/catalog/)

Here is my urls.py

urlpatterns = patterns('',
(r'^catalog/

And in the package preview my views.py

from django.shortcuts import render_to_response

# Create your views here.
def home(request):
    return render_to_response("index.html")

"index.html" is in the folder ecomstore/templates, the variable TEMPLATE_DIRS is set to this directory.

Strangely i got no debug trace, but the DEBUG variable is set to true
Does anybody know what's wrong?

, 'preview.views.home'), # Example: # (r'^ecomstore/', include('ecomstore.foo.urls')), # Uncomment the admin/doc line below to enable admin documentation: # (r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: # (r'^admin/', include(admin.site.urls)), )

And in the package preview my views.py

"index.html" is in the folder ecomstore/templates, the variable TEMPLATE_DIRS is set to this directory.

Strangely i got no debug trace, but the DEBUG variable is set to true
Does anybody know what's wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

御守 2024-10-11 02:42:04

您的 settings.py 中的 TEMPLATE_DIRS 是什么样的,以及您希望加载的磁盘上的 index.html 路径是什么并渲染?听起来它试图找到 index.html 但找不到它,但如果没有调试回溯,就很难判断。

What does your TEMPLATE_DIRS look like in your settings.py and what path is your index.html in on disk that you are expecting it to load and render? It sounds like it's trying to find index.html but cannot find it, but without the debug traceback it's tough to tell.

如若梦似彩虹 2024-10-11 02:42:04

作为解决方法,也许您可​​以尝试 http://localhost:8000/catalog/

我遇到了今天早上我的 Windows XP 机器上也出现了同样的情况。当我从使用 127.0.0.1 切换到 localhost 时,它就开始工作了。我仍然不知道我做了什么让它停止工作。

As a work-around, maybe you can try http://localhost:8000/catalog/

I ran into the same situation this morning on my Windows XP machine. When I switched from using 127.0.0.1 to localhost, it just started working. I still haven't figured out what I did to make it stop working.

小鸟爱天空丶 2024-10-11 02:42:04

这是您的根(项目级)URLconf,还是来自您的应用程序之一?如果它来自您的应用程序之一,它是否已正确包含在根 URLconf 中?

我问这个问题是因为如果 Django 确实正在读取您显示的代码,那么它应该可以工作。

另一个想法:该视图中是否有任何内容引发 Http404 异常?直接还是通过get_object_or_404

我还赞同上述请求,以分享完整的回溯。

Is this your root (project-level) URLconf, or is it from one of your apps? If it's from one of your apps, is it being properly included from the root URLconf?

I ask because the code you show should work, if Django is indeed reading it.

Another idea: is anything in that view raising an Http404 exception? Either directly, or via get_object_or_404?

I also second the requests above to share the full traceback.

醉生梦死 2024-10-11 02:42:04

我遇到这个问题是因为我在index.html 中大写了I。所以它正在寻找index.html,而我有Index.html。我花了一个小时才找到那个。只需仔细检查即可。

I had this problem because I capitalized the I in index.html. So it was looking for index.html and I had Index.html. Took me an hour to find that. Just double check.

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