form = IndexForm()とform_class = IndexFormと書く書き方の違いは何なのでしょうか?サンプルコードで、
def index(request): content = Userdata.objects form = IndexForm() return render(request,'index.html',{'content':content,'form':form}) class DetailView(generic.DetailView): model = Detail template_name = 'detail.html' form_class = IndexForm def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['form'] = self.form_class return context
と言うコードが出てきました。
indexメソッドでは
form = IndexForm()
と書いてIndexForm()を呼び出しており、DetailViewクラスでは
form_class = IndexForm
と書いてIndexFormを呼び出しており、同じFormを呼び出しているだけなのに、なぜこう書き方が違うのかを思います。
form = IndexForm()
でインスタンスを呼び出しているのはわかりますが、
form_class = IndexForm
でセットしているものは何なのかわかりません。また
context['form'] = self.form_class
ではインスタンスを生成しているのでしょうか?なぜこう書き方が違うのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/01/13 07:23