Django-在基于类的视图上使用reverse() [英] Django - using reverse() on Class-based views
本文介绍了Django-在基于类的视图上使用reverse()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Django项目中具有以下urls配置:
I have the following urls configuration in my Django project:
urlpatterns = patterns('',
(r'^my-view$', MyViewClass.as_view()),
)
是否可以使用 reverse()
函数获取上述视图的URL?
Is there a way to use the reverse()
function to get the url of the above view?
推荐答案
是的。
使用<$ c $的 name
参数c> url 函数定义URL的名称,然后您可以在该名称上使用 reverse
:
Use the name
argument of the url
function to define a name for the url, then you can use reverse
on this name:
from django.conf.urls import patterns, url
urlpatterns = patterns('',
url(r'^my-view$', MyViewClass.as_view(), name='my_view'),
)
reverse('my_view')
这篇关于Django-在基于类的视图上使用reverse()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文