views:

434

answers:

4

Very basic question, but I'm having trouble tracking down the answer on the web. I have a template, which I want to link to the django admin site (i.e. localhost:8000/admin). What is the code for this?

I'm imagining something like

<a href="{% url admin.site.root %}">link to admin panel</a>

However, when I try the above snippet I get:

Caught an exception while rendering:
  Reverse for 'project_name.django.contrib.admin.sites.root' with
  arguments '()' and keyword arguments '{}' not found.

Help?

+3  A: 

Which django version are you using? If you're using trunk, change your admin urlpatterns from:

(r'^admin/(.*)', admin.site.root)

to:

('^admin/', include(admin.site.urls))

And then you get a named URL pattern called 'admin_index' which you can refer to. See

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#reversing-admin-urls

for more information

oggy
+1  A: 

I think your suggestion is good for the latest version of Django. But I'm working in Django 1.0.2.

?

Edit: on 1.0.2, you can get the reverse admin url with the reverse function like this:reverse(django.contrib.admin.site.root, args=[''])Not sure how it would work with the url tag though.
oggy
A: 

Maybe a little wet (non-DRY), but what's wrong with simply href="/admin" ?

zooglash
+1  A: 

Try what Oggy is suggesting but then use ':' instead of '_' with the current Django:

<a href="{% url admin:index %}">link to admin panel</a>
Ro