Django - How to get admin url from model instance

前端 未结 5 433
情书的邮戳
情书的邮戳 2021-02-01 15:34

I\'m trying to send an email to a user when a new model instance is saved and I want the email to include a link to the admin page for that model instance. Is there a way to get

5条回答
  •  不知归路
    2021-02-01 16:13

    Just use this one liner that is also python 3 ready:

    from django.urls import reverse
    
    reverse('admin:{0}_{1}_change'.format(self._meta.app_label, self._meta.model_name), args=(self.pk,))
    

    More on this in the django admin site doc, reversing admin urls.

提交回复
热议问题