码迷,mamicode.com
首页 > 其他好文 > 详细

CSRF验证失败. 相应中断

时间:2015-10-25 13:32:56      阅读:2509      评论:0      收藏:0      [点我收藏+]

标签:

def login(request):
    if request.method == ‘POST‘:
        uf = LoginForm(request.POST)
        if uf.is_valid():
            #获取表单用户密码
            username = uf.cleaned_data[‘name‘]
            password = uf.cleaned_data[‘pwd‘]
            #获取的表单数据与数据库进行比较
            return HttpResponseRedirect(‘/homepage/‘)
    else:
        uf = LoginForm()
    return render_to_response(‘l.html‘,{‘uf‘:uf},context_instance=RequestContext(request))

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>登录</title>
</head>
 <style type="text/css">
    body{color:#efd;background:#453;padding:0 5em;margin:0}
    h1{padding:2em 1em;background:#675}
    h2{color:#bf8;border-top:1px dotted #fff;margin-top:2em}
    p{margin:1em 0}
  </style>
<body>
<h1>登录页面:</h1>
<form method = ‘post‘ enctype="multipart/form-data">
    {% csrf_token %}
    {{uf.as_p}}
    <input type="submit" value = "ok" />
</form>
</body>
</html>

 

CSRF验证失败. 相应中断

标签:

原文地址:http://www.cnblogs.com/linbinqiang/p/4908539.html

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!