Skip to main content
 首页 » 编程设计

python之为什么django不加载我的 View

2025年05月04日34mfrbuaa

当我尝试加载站点时收到“找不到页面”错误。(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 有人知道怎么回事吗?

请您参考如下方法:

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