Getting Django admin url for an object

前端 未结 9 1733
有刺的猬
有刺的猬 2020-12-02 03:51

Before Django 1.0 there was an easy way to get the admin url of an object, and I had written a small filter that I\'d use like this:

9条回答
  •  孤街浪徒
    2020-12-02 04:27

    I had a similar issue where I would try to call reverse('admin_index') and was constantly getting django.core.urlresolvers.NoReverseMatch errors.

    Turns out I had the old format admin urls in my urls.py file.

    I had this in my urlpatterns:

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

    which gets the admin screens working but is the deprecated way of doing it. I needed to change it to this:

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

    Once I did that, all the goodness that was promised in the Reversing Admin URLs docs started working.

提交回复
热议问题