如果我打印request.POST.username
并且request.POST.password
,我得到正确的数据。但我无法验证表格。我无法得到cleaned_data
。
视图.py
def login(request):
if request.method == 'POST':
form = LoginForm(request.POST)
if form.isValid():
print "coming"
return render_to_response('html/index.html')
else:
form = LoginForm()
c = {'logInForm': form, }
return render_to_response('html/index.html', c, RequestContext(request))
表格.py
from django import forms
class LoginForm(forms.Form):
username = forms.EmailField()
password = forms.CharField(max_length=50)
索引.html
<!DOCTYPE html>
<html>
<head>
.....
</head>
<body>
<div class="container">
<form class="form-signin" action="login" method="post">{% csrf_token %}
{{ logInForm.as_p }}
<input type="submit" value="Submit"/>
</form>
</div>
</body>
</html>