django自定义后台界面
Django csrf 两种方法设置form的实例第一种方法,在视图函数上边添加一条语句
|
@csrf_exempt |
例子:
|
@csrf_exempt def login(request): return render_to_response( 'app/login.html' , locals ()) |
上边的方法是取消csrf的防御机制。
第二种方法,给出例子,主要为在html的form里面加入{% csrf_token %}这句话,视图函数内加入render(request, 'app/breakdown_view.html', locals())
例子:
|
<li class = "container" > <form class = "form-signin" method = "POST" > { % csrf_token % } <h2 class = "form-signin-heading" >Please login in < / h2> <label for = "inputEmail" class = "sr-only" >Email address< / label> < input name = "loginEmail" type = "email" id = "inputEmail" class = "form-control" placeholder = "Email address" value = "{{myLogin.loginEmail}}" required autofocus> <label for = "inputPassword" class = "sr-only" >Password< / label> < input name = "loginPassword" type = "password" id = "inputPassword" class = "form-control" placeholder = "Password" required> <! - - <li class = "checkbox" > <label> < input type = "checkbox" value = "remember-me" > Remember me < / label> < / li> - - > <button class = "btn btn-lg btn-primary btn-block" type = "submit" >Login in < / button> < / form> < / li> <! - - / container - - > |
|
def login(request): return render(request, 'app/login.html' , locals ()) |
以上这篇Django csrf 两种方法设置form的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持开心学习网。
原文链接:https://blog.csdn.net/u013023781/article/details/61617589