Linking to the django admin site

柔情痞子 提交于 2019-11-27 05:35:14

问题


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?


回答1:


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

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



回答2:


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



来源:https://stackoverflow.com/questions/1022236/linking-to-the-django-admin-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!