为什么 django 不加载我的视图
当我尝试加载网站时,出现“找不到页面”错误。(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的
settings.py
中的TEMPLATE_DIRS
是什么样的,以及您希望加载的磁盘上的index.html
路径是什么并渲染?听起来它试图找到index.html
但找不到它,但如果没有调试回溯,就很难判断。What does your
TEMPLATE_DIRS
look like in yoursettings.py
and what path is yourindex.html
in on disk that you are expecting it to load and render? It sounds like it's trying to findindex.html
but cannot find it, but without the debug traceback it's tough to tell.作为解决方法,也许您可以尝试 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.
这是您的根(项目级)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.
我遇到这个问题是因为我在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.