我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用django.views.generic.FormView()。
def test_extends_form_view(self): """ The view should extend django FormView """ self.assertTrue(issubclass(CsvExportView, FormView))
def form_valid(self, form): username = form.cleaned_data['username'] password = form.cleaned_data['password'] user = authenticate(username=username, password=password) if user is not None: login(self.request, user) else: return HttpResponse('ID or PW incorrect') return super().form_valid(form) # class LoginFormView(FormView): # template_name = 'member/login.html' # form_class = LoginForm # success_url = reverse_lazy('photo:photo_list') # # def form_valid(self, form): # username = form.cleaned_data['username'] # password = form.cleaned_data['password'] # # user = authenticate(username=username, password=password) # if user is not None: # login(self.request, user) # else: # return HttpResponse('ID or PW incorrect') # return super().form_valid(form)
def get_context_data(self, **kwargs): context = super(FormView, self).get_context_data(**kwargs) context['layout'] = self.get_layout() return context