【发布时间】:2010-10-15 05:39:12
【问题描述】:
我的 urls.py 中有用于通用视图的代码;
infodict = {
'queryset': Post.objects.all(),
'date_field': 'date',
'template_name': 'index.html',
'template_object_name': 'latest_post_list',
}
urlpatterns += patterns('django.views.generic.date_based',
(r'^gindex/$', 'archive_index', infodict),
)
所以转到地址 /gindex/ 将使用带有 'index.html' 模板的通用视图。
但是由于我将在此 urlpattern 中拥有更多通用视图,我应该如何使用相同的 infodict 提供不同的模板名称?我不想使用大量的 infodict,也不能使用默认的模板名称。
请注意,这也适用于 infodict 中的模板对象名称。
感谢您的帮助!
编辑: 这是我在 stackoverflow 上的第一个问题,我对详尽的答案感到惊讶! 我更喜欢使用我不知道的 dict 构造函数。我发现使用 python 文档有点困难,因为我通常找不到我要找的东西!
再次感谢所有答案和不同的方法。
【问题讨论】:
标签: python django django-urls