博客地址:https://www.cnblogs.com/zylyehuo/
view.py
def get_tokens(request):
token = get_token(request)
return HttpResponse(token)
login.html
$.ajax({
url:"/get tokens/"
success: function (res{
console.log(res);
localStorage.setItem("token",res)
}
});
$(".login btn").click(function (){
$.ajax({
url:"/login/"
type:"post"
data:{
csrfmiddlewaretoken:localStorage.getItem("token")
user: $(".user").val(),
pwd: $(".pwd").val(),
},
success: function (res) {
console.log("res:",res);
if(res,state){
location.href = "/index/"
}else {
$(".err").html(res.msg)
}
}
}
}