Django : NoReverseMatch for HttpResponseRedirect with kwargs
django, python
Solution
When you are using `reverse` with `kwargs` parameters django tries to find a parameterized url route. In your example, matching route would be similar to
url(r'^test2/(?P<msg>\w+)/(?P<case>\w+)$','common.views.view2',name='my_view2')
Refer to `reverse` and `URLDispatcher` documentation for more details. Unfortunately, both URLDispatcher and reverse manuals are a little bit cryptic about this particuar feature.
Problem
I'm getting the following error: NoReverseMatch at /updatebooking/ Reverse for 'common.views.myview' with arguments '()' and keyword arguments '{'msg': "hello", 'case': 'success'}' not found. common/views.py ``` def view1(request): ... return HttpResponseRedirect(reverse('common.views.view2', kwargs= {"msg":"hello","case":"success"})) def view2(request,msg=None,case=None): ... ``` urls.py ``` url(r'^test1/$','common.views.view1',name='my_view1'), url(r'^test2/$','common.views.view2',name='my_view2'), ``` This line `reverse('common.views.view2', kwargs= {"msg":"hello","case":"success"})` is throwing the error. The error comes only when I use `kwargs`. Following codes work: ``` return HttpResponseRedirect(reverse('my_view2')) return HttpResponseRedirect(reverse('common.views.view2')) ``` Kindly help me resolve this.