Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse custom django Admin Site urls?

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

like image 789
armonge Avatar asked Sep 30 '11 16:09

armonge


People also ask

How do I find my Django admin url?

Open a browser on the Django admin site http://127.0.0.1:8000/admin/.

What is Django url reverse?

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.


2 Answers

Try: {% url admin:some_view %}

like image 135
Brandon Avatar answered Oct 13 '22 06:10

Brandon


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')
like image 20
Bobby Avatar answered Oct 13 '22 05:10

Bobby