我的模板" login_form.html":
<form class="form-signin" method="post" action=" {% url 'login_form' %}">
{% csrf_token %}
<h2 class="form-signin-heading">Please sign in</h2>
<input type="text" class="form-control" name="username">
<input type="password" class="form-control" name="password">
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me"> Remember me
</label>
</div>
<input type="submit" class="btn btn-lg btn-primary btn-block" value="Login">
<div>
<label>
<a href="#" value="forgot"> Forgot Password?</a>
</label>
<label class="pull-right">
<a href="#" value="register">Register</a>
</label>
</div>
</form>
我的views.py:
class LoginFormView(FormView):
form_class = LoginForm
template_name = 'pv_ui/login_form.html'
def post(self, request, *args, **kwargs):
print self, request
return render(request, template_name)
def form_valid(self, form):
print self, form
return HttpResponseRedirect(reverse('video'))
我的urls.py:
urlpatterns = patterns('pv_ui.views',
url(
regex=r'^login/$',
view=LoginFormView.as_view(),
name='login_form',
),
)
这是POST数据:
POST:<QueryDict: {u'username': [u'aaa@gmail.com'], u'csrfmiddlewaretoken': [u'pphxKPkOhIe0Yk7MqQSj2NYtL2iFlC3b'], u'password': [u'heretherehere']}>,
我偶然发现了这个问题,表单没有验证。帖子键的值被括在括号内,不知道为什么会发生这种情况或是否应该发生?请指出我的错误。谢谢。
重要信息: Django的== 1.7.1