2015-12-25 114 views
1

我剛剛開始與Django的旅程,我無法弄清楚我做錯了什麼。對不起,這個簡單的問題。Django Python找不到頁面(404)

新西蘭移民局/ urls.py

urlpatterns = [ 
url(r'', include('planner.urls')), 
url(r'^admin/', include(admin.site.urls)),] 

規劃師/ urls.py

urlpatterns = [ 
url(r'^$', views.main_page), 
url(r'^/student/$', views.student, name='student'),] 

和我base.html文件HREF:

<a href="/student/">Student</a> 

而且我的錯誤:

Request URL: http://127.0.0.1:8000/student/ Using the URLconf defined in inz.urls, Django tried these URL patterns, in this order: ^$ ^/student/$ [name='student'] ^admin/ The current URL, student/, didn't match any of these.

回答

3

^/student/$刪除前導斜線

url(r'^student/$', views.student, name='student'), 

僅供參考,在URL調度文檔有一個related example

There’s no need to add a leading slash, because every URL has that. For example, it’s ^articles , not ^/articles .

+0

這是工作。謝謝! – kkkkk

+0

這是正確的。 r'^之後無需添加前導斜槓 –