python Django管理员URL模板标签
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Django管理员URL模板标签相关的知识,希望对你有一定的参考价值。
# Usage: <a href="{% admin_url model_instance %}">admin edit page</a>
from django.core import urlresolvers
from django.contrib.contenttypes.models import ContentType
from django import template
register = template.Library()
@register.simple_tag
def admin_url(instance):
try:
content_type = ContentType.objects.get_for_model(instance.__class__)
return urlresolvers.reverse("admin:%s_%s_change" % (content_type.app_label, content_type.model), args=(instance.id,))
except:
return ""
以上是关于python Django管理员URL模板标签的主要内容,如果未能解决你的问题,请参考以下文章