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?
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')
来源:https://stackoverflow.com/questions/13193350/django-reverse-class-based-views-by-function-name-do-not-work