0
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>}
내가 여기 실종 무엇 : 은 그냥 빈 객체를 제공 밝혀?
아니, fictive_form은 아직 없음입니다입니다, 당신의 모델 템플릿에서
을 위해 존재한다. CreateView가 어쨌든 모델을 필요로하는 이유는 모르겠습니다. 양식 컨텍스트 변수를 사용하면 잘 작동합니다. – Adrien