1)在app里创建一个forms.py文件
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #!/usr/bin/env python 2 #_*_coding:utf-8_*_ 3 4 5 from django import forms 6 from pip._vendor.pkg_resources import require 7 8 class Alogin(forms.Form): 9 username = forms.CharField() 10 email = forms.EmailField(required=True)
2)创建view文件
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 from web.form import Alogin 2 3 def Alogins(request): 4 repiter = Alogin() 5 if request.method == 'POST': 6 form = Alogin(request.POST) 7 if form.is_valid(): 8 data = form.cleaned_data 9 print data 10 else: 11 print form.errors.as_json() 12 13 return render_to_response('regrite.html',{'form':repiter})
3)创建html文件
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Insert title here</title> 6 </head> 7 <body> 8 <form action='/web/alogin/' method='POST'> 9 用户名:{{form.username}} 10 <br/> 11 邮箱:{{form.email}} 12 <br/> 13 <input type='submit' value='提交'><span style='color:red'>{{status}}</span> 14 <!-- 自带的方法 --> 15 <br/> 16 {{form.as_table}} 17 <input type='submit' value='提交'> 18 </form> 19 </body> 20 </html>