【发布时间】:2013-06-11 14:44:12
【问题描述】:
我很难为 django 的基于通用类的视图设置上下文对象名称。
class FictiveCreateView(generic.CreateView):
context_object_name = 'fictive_form'
form_class = forms.FictiveForm
template_name = 'fictive/create_fictive.html'
def get_context_data(self, **kwargs):
context = super(generic.CreateView, self).get_context_data(**kwargs)
print context
我认为设置context_object_name = 'fictive_form' 会更改上下文对象的名称。
原来它只是给出了一个空对象:
{'fictive_form': None, 'form': <fictive.forms.FictiveForm object at 0x7f925807a9d0>, u'view': <fictive.views.FictiveCreateView object at 0x7f925807aa50>}
我在这里错过了什么?
【问题讨论】:
标签: django django-generic-views