0

我有一个具有 template_name 字段的模型,并且我有这个通用视图:

url(r'^/post/(?P<slug>[a-zA-Z0-9_.-]+)$', 'django.views.generic.list_detail.object_detail', {
        "template_object_name" : "post",
        'template_name': 'post_details.html'
    }, 'index')

如何将“post_details.html”中的模板名称替换为帖子中的模板名称?

4

1 回答 1

2

有一个 template_name_field 参数。顺便说一句,您缺少查询集 arg。它看起来像这样:

url(r'^/post/(?P<slug>[a-zA-Z0-9_.-]+)$', 'django.views.generic.list_detail.object_detail', {
        "queryset": Post.objects.all(),
        "template_object_name" : "post",
        'template_name_field': 'template_name'
    }, 'index')
于 2010-08-05T22:33:04.117 回答