当前位置: 首页>>代码示例>>Python>>正文


Python generic.FormView方法代码示例

本文整理汇总了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,))) 
开发者ID:DavidCain,项目名称:mitoc-trips,代码行数:25,代码来源:winter_school.py

示例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) 
开发者ID:F0RE1GNERS,项目名称:eoj3,代码行数:19,代码来源:views.py

示例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)) 
开发者ID:gavinwahl,项目名称:django-u2f,代码行数:6,代码来源:views.py


注:本文中的django.views.generic.FormView方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。