Getting Django admin url for an object

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

    If you are using 1.0, try making a custom templatetag that looks like this:

    def adminpageurl(object, link=None):
        if link is None:
            link = object
        return "%s" % (
            instance._meta.app_label,
            instance._meta.module_name,
            instance.id,
            link,
        )
    

    then just use {% adminpageurl my_object %} in your template (don't forget to load the templatetag first)

提交回复
热议问题