本文整理汇总了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))