Django reverse class based views by function name do not work

橙三吉。 提交于 2019-12-01 15:53:02

问题


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?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!