Getting Django admin url for an object

前端 未结 9 1711
有刺的猬
有刺的猬 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:36

    There's another way for the later versions, for example in 1.10:

    {% load admin_urls %}
    Add user
    Delete this user
    

    Where opts is something like mymodelinstance._meta or MyModelClass._meta

    One gotcha is you can't access underscore attributes directly in Django templates (like {{ myinstance._meta }}) so you have to pass the opts object in from the view as template context.

提交回复
热议问题