Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django reverse class based views by function name do not work

According to the django docs, viewname is either the function name or the url pattern name. But reversing an url like this 'reverse(MyView.as_view())' turns into a NoReverseMatch exception. Is there any way to reverse class based view by function name?

like image 208
user1603806 Avatar asked Nov 02 '12 10:11

user1603806


1 Answers

You can either used named url patterns or you can do something like the following (in your views.py)

my_function = MyView.as_view()

now reverse will work: reverse('myviews.my_function')

like image 197
Timmy O'Mahony Avatar answered Oct 07 '22 23:10

Timmy O'Mahony