[Fixed]-How can I generate a url to a particular item in the Django Admin Site from a view?

22👍

You can get the url in the view, using reverse,

object_change_url = reverse('admin:myapp_mymodel_change', args=(obj.id,))

Or in the template, using the url tag

{% url 'admin:myapp_mymodel_change' obj.id %}

or

{% load admin_urls %}
{% url opts|admin_urlname:'change' obj.id %}">

Note the above url tag syntax is for Django >= 1.5.

For more information, see the Django docs on reversing admin urls.

Leave a comment