Opened 9 years ago

Closed 9 years ago

#8564 closed (duplicate)

newforms-admin doesn't support linking to it via {% url %} or reverse()

Reported by: Ilya Semenov Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords: newforms-admin reverse url
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


In the old admin, that was possible to have a link to the admin area in the UI, like:

{% if user.is_staff %}
    <a href="{% url django.contrib.admin.views.main.index %}">Admin area</a>
{% endif %}

or even:

<a href="{% url django.contrib.admin.views.main.change_stage "app","model", %}">Edit instance</a>

In newforms-admin, that crashes with:

Reverse for '' not found.

I do realize that is now a Site instance, not a module, that's why {% url %} will never work for it.
However, I can't see how to put a link to the admin area now?

Currently I'm using the following hack:

urlpatterns = # ...
        (r'^admin/(.*)', 'views.admin_site_root'),

# ...

def admin_site_root(request, url):
        return, url)

and then:

<a href="{% url views.admin_site_root "" %}">Admin</a>

which is pretty ugly (since of complete redundancy) but solves the problem.

I defenitely think there should be a standard way to pull the admin site urls. I can suggest two approaches:

  1. Extend reverse() and {% url %} to recognize/understand bound methods, in particular
  1. Under django.contrib.admin.templatetags, create a set of tags like {% admin %} and {% admin_change_list "app","model" %}

Change History (3)

comment:2 Changed 9 years ago by Ilya Semenov

Thanks, I overlooked the named patterns. That partly solves the problem: with a named pattern, I actually can point to the admin root like {% url admin "" %}

That is still not possible to link to a particular admin page, though, e.g. have something like {% url admin "/app/model/" + %}, which was possible in the old admin app.

comment:3 Changed 9 years ago by Matt McClanahan

Resolution: duplicate
Status: newclosed

Duplicate of #6470.

Note: See TracTickets for help on using tickets.
Back to Top