是否有办法撤消添加到自定义django AdminSite的网址,例如
class MyAdminSite(AdminSite):
def get_urls(self):
urls = super(MyAdminSite, self).get_urls()
my_urls = patterns('',
url(r'some_view/$',self.admin_view( SomeView.as_view()), name='some_view' ),
)
return my_urls + url
myadmin = MyAdminSite(app_name='my_admin')
url(r'^admin/', include(my_admin.urls)),
如何撤消some_view
答案 0 :(得分:10)
尝试:{%url admin:some_view%}
答案 1 :(得分:3)
或者,如果您为管理网站定义了一个名称,如下所示:
class ExplorerAdmin(admin.AdminSite):
def __init__(self, *args, **kwargs):
super(ExplorerAdmin, self).__init__(*args, **kwargs)
self.name = 'explorer_admin'
self.app_name = 'rql'
def get_urls(self):
parent_patterns = super(RQLExplorerAdmin, self).get_urls()
dashboard_patterns = [
url(r'^$', admin.site.admin_view(TemplateView.as_view(template_name='explorer.html')), name="explorer")
]
return dashboard_patterns + parent_patterns
通过使用您的自定义网站名称应用命名空间来完成撤消网址,如下所示:
reverse('explorer_admin:explorer')