user2994682
user2994682

Reputation: 503

Django: Getting a link to admin page in a template

I'm trying to add a link in my django template to a page handled by the default admin console. The setup is below, I don't believe the {% url %} part of the equation is right and I'm getting the following error:

Reverse for 'profile_ProfileModel' with arguments '()' and keyword arguments '{}' not found.

How do I correct this and link to the admin console from the template.

template.html

<a href="{% url 'admin:profiles_ProfileModel' %}">Profiles</a>

profiles.models.py

class Profile (models.Model)

profiles.admin.py

class ProfileAdmin (admin.ModelAdmin)
    admin.site.register (Profile, ProfileAdmin)

url.py

urlpatterns = patterns("", url(r"^admin/", include(admin.site.urls)),)

Upvotes: 3

Views: 6941

Answers (1)

Alasdair
Alasdair

Reputation: 308889

The name of the changelist url for a model is {{ app_label }}_{{ model_name }}_changelist. In your case, if the app_label is profiles and the model in Profile, the view name would be profiles_profile_changelist.

Try the following:

<a href="{% url 'admin:profiles_profile_changelist' %}">Profiles</a>

See the Django docs on reversing admin urls for more information.

Upvotes: 9

Related Questions