Django : Passing multiple args in HttpResponseRedirect reverse function
I'm trying to pass 开发者_StackOverflow中文版multiple args in django's HttpResponseRedirect reverse function, but I keep getting this error
Reverse for 'DemoVar.views.success' with arguments '()' and keyword arguments '{'company': u'Company ', 'sid': 47606734}' not found.
#Calling function
return HttpResponseRedirect(reverse('DemoVar.views.success',kwargs={'sid':int(ph), 'company':company}))
#Function definition
def success(request, sid, company):
#urls.py
url(r'^success/(?P<sid>[\d]+)/(?P<company>[\w\d-]+)/$','success', name='DemoVar_success'),
I tried passing 'args' in reverse function, but with similar error. Please help.
Update: Tried passing the args as a tuple. The output remains same.
return HttpResponseRedirect(reverse('DemoVar.views.success',args=(ph, company,)))
#Error
Reverse for 'DemoVar.views.success' with arguments '(47606734, 'Dummy Company')' and keyword arguments '{}' not found.
My regex inside urls.py for corresponding function url was wrong. Apparently Django looks at urls.py to figure out the type of inputs for the view function, which in my case was 'DemoVar.views.success'. Since the url's regex didn't allow for 'spaces', django gave an error. I changed to regex to accommodate an input containing spaces.
url(r'^success/(?P<sid>[\d]+)/(?P<company>[\s\w\d-]+)/$','success', name='DemoVar_success'),
Your URL is named DemoVar_success
not DemoVar.views.success
.
精彩评论