0

我知道这听起来像是一个愚蠢的问题,但我知道是否需要重新编译 Python 代码或者由处理 Python 代码的服务器完成(绑定/渲染)?

我问你是因为我已经开始了一个示例项目,并且在向页面添加链接时出现“找不到页面”(404 错误)

Using the URLconf defined in httpi.urls, Django tried these URL patterns, in this order:
^$
^piface/
The current URL, mypage.html, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

Python 代码如下所示:

from django.conf.urls import patterns, include, url
from django.conf import settings

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('',
    url(r'^$', 'httpi.views.index'),
    url(r'^/mypage.html', 'httpi.views.index'),
    url(r'^piface/', include('httpiface.urls')),

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

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

1 回答 1

1

尝试更改url(r'^/mypage.html', 'httpi.views.index'),url(r'^mypage.html/$', 'httpi.views.index'),.

正则表达式看起来像它有一个额外的起始斜线,我猜这就是把它扔掉的原因。错误消息说它无法识别您输入的 url,并有用地指出您可能会在其他指定的 url 之一处获得有效响应。或者,根据您在此处显示的路由,如果您在基本服务器 url 之外没有输入任何页面(可能http://localhost:8000/),它会将您带到与 mypage.html 中指定的视图相同的视图。

于 2013-05-13T01:22:40.870 回答