當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。