views
def test_user(request):
print('start')
if request.method=='POST':
print('goon_test_user')
user = request.POST.get('user')
passwd = request.POST.get('passwd')
print(user,passwd)
print('#####')
if models.UserToPasswd.objects.filter(user=user,passwd=passwd).first():
print('')
dic = {'user':user,'status': '', 'msg': '用户名或密码错误'}
dic_dump=json.dumps(dic)
###
obj = HttpResponse(dic_dump)
obj.set_cookie('is_login',True,max_age=100)
obj.set_cookie('user',user)
###
return obj else:
print('')
dic = {'user':user,'status':'','msg':'用户名或密码错误'}
dic_dump = json.dumps(dic)
return HttpResponse(dic_dump) else:
return render(request,'test_user.html') def test2_user(request):
if request.method=='POST':
user = request.POST.get('user')
passwd = request.POST.get('passwd')
models.UserToPasswd.objects.create(user=user,passwd=passwd)
# token =request.POST
return render(request,'time_go.html',locals())
# return render(request,'time_go.html',locals())
return render(request,'sign_in.html') def success(request,user):
print('xxxxxxxx')
print(request.COOKIES)
if not request.COOKIES.get('is_login'):
return redirect("/test_user/")
user= request.COOKIES.get('user')
# return HttpResponse('Hello sir %s'%user)
return render(request,'index.html',locals())

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>auth</title>
<script src="/static/jquery-3.3.1.js"></script>
{# <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js "></script>#}
{# <link rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css">#}
</head>
<style>
.hide{
display: none;
}
</style>
<body> {#test#}
{#<input type="text" id="in1"> + <input type="text" id="in2"> = <input type="text" id="in3"> <button class="sub">submit</button>#}
{#<hr>#} <form action="" method="">
{% csrf_token %}
<h2>请输入登陆信息</h2>
<p>用户名:<input type="text" class="u_p" id="user"></p>
<p>密码: <input type="password" class="u_p" id="passwd"></p>
{# <button class="auth">登陆</button> <span class="err hide"></span>#}
<input class="auth" type="button" value="登陆"> <span class="err hide"></span>
</form> <script>
$(".auth").click(function () { $.ajax({
url:"/test_user/",
type:'post',
data:{'user':$('#user').val(), {#发送数据到上方的url中,type可以选择,在视图的request中可以将数值取出来,用get字典中的name即‘in1’#}
'passwd':$('#passwd').val(),
'csrfmiddlewaretoken':$('[name=csrfmiddlewaretoken]').val(), {#这个是post请求时候用的验证,相当于表单的验证.#}
}, success:function (data) { {#这里的data是服务器返回来的数据,即return HttpResponse(str(in3))中HttpResponse中的值#}
var data =JSON.parse(data)
console.log(data)
console.log("---------") var user = data['user']
console.log(user)
var status = data['status']
var msg= data['msg']
if (status=='1'){
temp="/success/ppp";
temp = temp.replace('ppp',user)
location.href=temp
$('.err').addClass('hide')
} else {
$('.err').text(msg)
$('.err').removeClass('hide') } {##}
},
{# error:function (data) {#}
{# var data#}
{# #}
{# #}
{# } #} }) }) {# $("#auth").onclick(function () {#}
{# $.ajax(#}
{# {url:'/ajax_auth/',#}
{# type:'post',#}
{# data:{ 'user':$('#user').val(),#}
{# 'passwd':$("#passwd").val(),#}
{# 'csrfmiddlewaretoken':$("[name=csrfmiddlewaretoken]").val()#}
{# },#}
{# success:function () {#}
{##}
{##}
{##}
{# }#}
{##}
{# }#}
{# )#}
{##}
{# })#}
{# 绑定焦点事件 #}
{# $(".u_p").onfocus(function () {#}
{# $.ajax(#}
{# {url:"/test_user/",#}
{# type:'post',#}
{# data:{ 'user':$('.u_p').val(),#}
{# 'csrfmiddlewaretoken':$('[name=csrfmiddlewaretoken]').val(),#}
{# },#}
{# success:function (data) {#}
{# if (data.get('user')==0){#}
{##}
{# }#}
{##}
{# }#}
{# }#}
{##}
{# )#}
{##}
{# })#}
{##} </script>
</body>
</html>

xxx

cookies_ajax的更多相关文章

随机推荐

  1. USB-IF协会公布最新PD3.0(PPS)协议认证芯片和产品名单

    原文: http://www.chongdiantou.com/wp/archives/25510.html 2017年的骁龙技术峰会高通带来了第一款兼容USB PD3.0(PPS)的QC4+充电器, ...

  2. Ubuntu 搭建 Zerotier One MOON 根目录服务器

    原文转摘:http://www.congan.wang/archives/947 博主倒腾了一天,总算搞定了,主要是受到各种搭建教程的错误引导,导致关键过程错误.官网的MOON搭建教程:https:/ ...

  3. php安装imagemagick扩展 常见问题与解决方案(win平台)

    1.写在前面 1-1.ImageMagick介绍 ImageMagick是一套功能强大.稳定而且开源的工具集和开发包,可以用来读.写和处理超过89种基本格式的图片文件,包括流行的TIFF.JPEG.G ...

  4. android实现3D Gallery 轮播效果,触摸时停止轮播

    1.轮播控件涉及到的两个类 CarouselViewPager.java public class CarouselViewPager extends ViewPager { @IntDef({RES ...

  5. 00001 - Linux 上的 Shebang 符号(#!)

    使用Linux或者unix系统的同学可能都对#!这个符号并不陌生,但是你真的了解它吗? 本文了将给你简单介绍一下Shebang(”#!”)这个符号. 首先,这个符号(#!)的名称,叫做”Shebang ...

  6. Git及GitLab使用手册

    一.GitBash安装与使用 参考: https://www.cnblogs.com/jasonxu19900827/p/7823089.html 二.SourceTree安装与使用 SourceTr ...

  7. int main(int argc,char* argv[])浅析

    int main(int argc,char* argv[])浅析 argc : 指输入参数个数,默认值1,就是执行程序名称 argv[] : 输入参数数组指针 举个栗子: 1. 编写一个argc.c ...

  8. python中编码问题

    各种编码在内存中所占的大小: ascii: 英文:8bit (1B) uft-: 英文:8bit (1B) 中文:24bit (3B) GBK: 英文:8bit (1B) 中文:16bit (2B) ...

  9. Json1:使用gson解析、生成json

    Json解析: 1.json第三方解析包:json-lib.gson.jackson.fastjson等2.Google-gson只兼容jdk1.5版本以上:JSON-lib分别支持1.4和1.53. ...

  10. jQuery选择器详解

    根据所获取页面中元素的不同.可以将jQuery选择器分为:四大类,其中过滤选择器在分为六小类 jQuery选择器 基本选择器   层次选择器   过滤选择器 简单过滤选择器 内容过滤选择器 可见性过滤 ...