简体   繁体   English

Django重定向没有反向匹配错误

[英]django redirect no reverse match error

Here is my main project timecapture/urls.py content: 这是我的主要项目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')
]

And here is an app inside main project timesheet/urls.py: 这是主项目时间表/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),
]

I am unable to redirect to 'timesheet' url. 我无法重定向到“时间表”网址。 I am using the following command: 我正在使用以下命令:

return redirect('timesheet')

But this is working: 但这是可行的:

return redirect('/timesheet/')

Exact error is `enter code here 确切的错误是在这里输入代码

django.core.urlresolvers.NoReverseMatch: Reverse for 'timesheet' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

Btw I am using latest django 1.9.2 with python 3.4 顺便说一句我正在使用最新的Django 1.9.2与Python 3.4

You don't have a URL named "timesheet". 您没有名为“时间表”的URL。 You've got an include with that name, but not the views. 您有一个包含该名称的包含项,但没有视图。

Remove name='timesheet' from the include in the main urls.py, and add it instead to the index url in timesheet/urls.py. 从主urls.py中的包含中删除name='timesheet' ,然后将其添加到timesheet / urls.py中的索引URL中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM