Django无法找到urlpath

时间:2014-07-23 13:05:08

标签: python django url django-urls

我试图去127.0.0.1:8000/poll/它没有打开,但我可以去/ poll / 20 /结果。 我只是添加其他民意调查和基本网址 - > / poll / stop打开。 在我添加详细信息,结果,投票功能/网址之前,打开投票索引没有问题。

以下是我的代码: 在view.py

from django.shortcuts import render
from django.http import HttpResponse


def index(request):
    return HttpResponse("Hello, World. You are at the poll index.")

def detail(request, poll_id):
    return HttpResponse("You are looking at poll %s" %poll_id)

def results(request, poll_id):
    return HttpResponse("You are looing at the results of poll %s" % poll_id)

def vote(request, poll_id):
    return HttpResponse("You are voting on poll %s" %poll_id)

在民意调查/ urls.py

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


urlpatterns = patterns( '', 
                   url(r'^Ş', views.index, name='index'),
                   url(r'^(?P<poll_id>\d+)/$', views.detail, name='detail'),
                   url(r'^(?P<poll_id>\d+)/results/$', views.results,name='results'),
                   url(r'^(?P<poll_id>\d+)/vote/$', views.vote, name='vote'),
              )

在mysite / urls.py

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

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',

   url(r'^$', 'sign_ups.views.home', name='home'),
   url(r'^admin/', include(admin.site.urls)),

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

)

1 个答案:

答案 0 :(得分:0)

在MySite.urls中,

您已将民意调查网址提及为polls,并将网址指定为poll

更改其中任何一个以使应用正常运行。