本文整理匯總了Python中django.views.generic.FormView方法的典型用法代碼示例。如果您正苦於以下問題:Python generic.FormView方法的具體用法?Python generic.FormView怎麽用?Python generic.FormView使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.views.generic
的用法示例。
在下文中一共展示了generic.FormView方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: form_invalid
# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import FormView [as 別名]
def form_invalid(self, form):
""" Provide custom behavior on invalidation to compensate for lack of template.
The default behavior from FormView is to try rendering a template with
errors for the user. However, since the attended lectures form is
tremendously simple (a hidden input with participant ID, and a submit
button), there really isn't any errors we can give to the user.
We can expect an invalid form submission when:
1. A participant loads the attendance form (while self-submission is allowed)
2. The Winter School chairs disable lecture sign-in
3. The participant then tries to submit the form, but is not allowed
"""
participant = form.cleaned_data['participant']
# Notifications aren't shown when viewing other participants
if participant == self.request.participant:
messages.error(
self.request, "Unable to record your attendance at this time."
)
# (note that some participants may not have access to this route!)
return redirect(reverse('view_participant', args=(participant.pk,)))
示例2: form_valid
# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import FormView [as 別名]
def form_valid(self, form):
codeforces.create_task(form.cleaned_data["answer"], self.request.user)
return super().form_valid(form)
# class PackageUpload(PolygonBaseMixin, FormView):
# class UploadForm(forms.Form):
# file = forms.FileField()
#
# form_class = UploadForm
#
# def get_success_url(self):
# return reverse("polygon:packages")
#
# def form_valid(self, form):
# codeforces.create_task(0, self.request.user, init_file=form.cleaned_data["file"])
# return super().form_valid(form)
示例3: form_invalid
# 需要導入模塊: from django.views import generic [as 別名]
# 或者: from django.views.generic import FormView [as 別名]
def form_invalid(self, form):
# Should this go in Django's FormView?!
# <https://code.djangoproject.com/ticket/25548>
return self.render_to_response(self.get_context_data(form=form))