0

我目前被困在 django 教程的第 3 部分。民意调查views.py是...

from django.http import HttpResponse

def index(request):
    return HttpResponse("<strong>Welcome to the poll index page!</strong>")

民意调查网址是...

from django.conf.urls import patterns, url
from polls import views

urlpatterns = patterns('',
                   url(r'^$', views.index, name='index')
                   )

我的网站网址是...

from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
           url(r'^polls/', include('polls.urls')),
           url(r'^admin/', include(admin.site.urls)),
          )

每次我运行它,我都会得到......

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

^polls/
^admin/

The current URL, , didn't match any of these.

似乎无法弄清楚这里出了什么问题,有什么提示吗?

4

1 回答 1

0

这里的问题是您指向localhost:8000尚未由您定义,您定义的路由是localhost:8000/adminlocalhost:8000/polls。访问这些以使您的网址正常工作或尝试更​​改以下网址以在localhost:8000本身进行民意调查

from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
           url(r'^/$', include('polls.urls')),
           url(r'^admin/$', include(admin.site.urls)),
          )

希望能帮助到你。

于 2013-10-12T04:11:55.383 回答