我按照Django官网的例子写了第一个view,mysite/polls/views.py文件内容:
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello world. You're at the polls index.")
mysite/urls.py文件内容:
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)),
)
mysite/polls/urls.py文件内容
from django.conf.urls import patterns, url
from polls import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
)
运行server,并访问:http://localhost:8000/polls/
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/polls/
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
1. ^admin/
The current URL, polls/, 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.
在django的URLpattern列表中居然没有^polls,不知道啥原因,麻烦各位高手指教。