-
显示表单的视图。出错时,重新显示带有验证错误的表单;成功后,重定向到一个新的 URL。
祖先 (MRO)
此视图从以下视图继承方法和属性:
django.views.generic.base.TemplateResponseMixin
django.views.generic.edit.BaseFormView
django.views.generic.edit.FormMixin
django.views.generic.edit.ProcessFormView
- View
示例 myapp/forms.py:
from django import forms class ContactForm(forms.Form): name = forms.CharField() message = forms.CharField(widget=forms.Textarea) def send_email(self): # send email using the self.cleaned_data dictionary pass
示例 myapp/views.py:
from myapp.forms import ContactForm from django.views.generic.edit import FormView class ContactFormView(FormView): template_name = 'contact.html' form_class = ContactForm success_url = '/thanks/' def form_valid(self, form): # This method is called when valid form data has been POSTed. # It should return an HttpResponse. form.send_email() return super().form_valid(form)
示例 myapp/contact.html:
<form method="post">{% csrf_token %} {{ form.as_p }} <input type="submit" value="Send message"> </form>
本文介绍 django.views.generic.edit.FormView
的用法。
声明
class django.views.generic.edit.FormView
相关用法
- Python Django Form.default_renderer用法及代码示例
- Python Django Form.as_p用法及代码示例
- Python Django Form.as_table用法及代码示例
- Python Django Form.is_multipart用法及代码示例
- Python Django Form.fields用法及代码示例
- Python Django Form.prefix用法及代码示例
- Python Django Form.as_ul用法及代码示例
- Python Django Form.cleaned_data用法及代码示例
- Python Django ForeignKey.on_delete用法及代码示例
- Python Django ForeignKey.related_name用法及代码示例
- Python Django ForeignKey.related_query_name用法及代码示例
- Python Django ForeignKey.limit_choices_to用法及代码示例
- Python Django File.save用法及代码示例
- Python Django Field.description用法及代码示例
- Python Django Feature.get用法及代码示例
- Python File next()用法及代码示例
- Python File tell()用法及代码示例
- Python Django Floor用法及代码示例
- Python Django Field.type_name用法及代码示例
- Python Django Feed.item_geometry用法及代码示例
- Python Django Feed用法及代码示例
- Python Django Field.help_text用法及代码示例
- Python File seek()用法及代码示例
- Python Django Feature.fid用法及代码示例
- Python OpenCV Filter2D()用法及代码示例
注:本文由纯净天空筛选整理自djangoproject.com大神的英文原创作品 django.views.generic.edit.FormView。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。