2015-06-02 47 views
0

我正在關注this教程來學習Django。我是一個首發。 我的urls.py文件下面的代碼在Django中找不到頁面

from django.conf.urls import include, url 
from django.contrib import admin 
from . import views 

urlpatterns = [ 
    url(r'^$', views.index, name='index'), 
    url(r'^polls/', include('polls.urls')), 
    url(r'^admin/', include(admin.site.urls)), 

] 

我views.py文件

from django.shortcuts import render 

def index(request): 
return HttpResponse("Hello, world. You're at the polls index.") 

當我嘗試訪問URL日在http://127.0.0.1:8000/polls/我的系統它給沒有發現消息的頁面。我究竟做錯了什麼? 這是版本差異的問題嗎?

以下是錯誤 enter image description here

+0

是否包含在'INSTALLED_APPS'您的應用程序在你的'settings.py'? – Leistungsabfall

+0

@Leistungsabfall是的,我已經包括了。 –

+0

那麼polls.urls中有什麼? –

回答

1

如果您的polls目錄中的urls.py文件不具有此模式,則會出現此錯誤。創建urls.py意見調查目錄中的文件,並添加下列URL模式

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

urlpatterns = patterns('', 
# ex: /polls/ 
url(r'^$', views.index, name='index'), 
) 
+0

我已經試過,但它不起作用 –

+1

你可以顯示你的民意調查/ urls.py文件。因爲如果有這種模式,那麼錯誤頁面也會顯示出來。目前它並沒有顯示在你的屏幕截圖中。 –

+0

我編輯了這個問題。請檢查 –

1

確定的截圖,所以如果你想使用/polls/這個網址, 您polls.urls應類似於這樣(爲django1.8):

from django.conf.urls import url 
from polls.views import BasePollView, AnotherPollView 

urlpatterns = [ 
    url(r'^$', BasePollView.as_view()), 
    url(r'^another-url/$', AnotherPollView.as_view()) 
] 

/polls/ - > BasePollView

/polls/another-url/ - > AnotherPollView