[英]django redirect no reverse match error
這是我的主要項目timecapture / urls.py內容:
from django.conf.urls import url,include
from django.contrib import admin
from django.core.urlresolvers import reverse_lazy
from . import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$',views.index,name='index'),
url(r'^login/$',views.auth_login,name='auth_login'),
url(r'^logout/$',views.auth_logout,name='auth_logout'),
url(r'^timesheet/',include('timesheet.urls'),name='timesheet')
]
這是主項目時間表/urls.py中的一個應用程序:
from django.conf.urls import url,include
from django.contrib import admin
from django.http import HttpResponse
from . import views
urlpatterns = [
url(r'^$',views.index),
]
我無法重定向到“時間表”網址。 我正在使用以下命令:
return redirect('timesheet')
但這是可行的:
return redirect('/timesheet/')
確切的錯誤是在這里輸入代碼
django.core.urlresolvers.NoReverseMatch: Reverse for 'timesheet' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
順便說一句我正在使用最新的Django 1.9.2與Python 3.4
您沒有名為“時間表”的URL。 您有一個包含該名稱的包含項,但沒有視圖。
從主urls.py中的包含中刪除name='timesheet'
,然后將其添加到timesheet / urls.py中的索引URL中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.