forms 有两个作用: 1、生产html 2、验证用户输入
#forms.py
from django import forms
class ALogin(forms.Form):
username = forms.CharField(required=True)
email = forms.EmailField()
ip = forms.GenericIPAddressField()
#app03/views.py
def index(request):
obj = forms.ALogin()
if request.method == 'POST':
checkForm = forms.ALogin(request.POST)
checkResult = checkForm.is_valid()
print(checkResult)
return render_to_response('app03/index.html',{'data':obj})
=======================================
<h1>Form</h1>
<form action="/app03/login/" method='POST'>
<div>
<div>
{{data.username}}
</div>
<div>
{{data.email}}
</div>
<div>
{{data.ip}}
</div>
</div>
<div>
<input type = 'submit' value="提交"/><label style="color:red">{{ status }}</label>
</div>
</form>