定义 FormView 派生类时:
class PrefsView(FormView):
template_name = "prefs.html"
form_class = MyForm # What's wrong with this?
def get(self,request):
context = self.get_context_data()
context['pagetitle'] = 'My special Title'
context['form'] = MyForm # Why Do I have to write this?
return render(self.request,self.template_name,context)
我预计context['form'] = MyForm
不需要该行,因为form_class
已定义,但没有它{{ form }}
不会传递给模板。
我做错了什么?