Is there a way to reverse URLs added to a custom django AdminSite, for example
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)),
How do i reverse some_view
Open a browser on the Django admin site http://127.0.0.1:8000/admin/.
the reverse function allows to retrieve url details from url's.py file through the name value provided there. This is the major use of reverse function in Django. Syntax: Web development, programming languages, Software testing & others. from django.urls import reverse.
Try: {% url admin:some_view %}
alternatively, if you've defined a name for your admin site like so:
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
reversing the url would be done by applying namespacing using your custom sites' name, like so:
reverse('explorer_admin:explorer')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With