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. java学习——异常处理机制

    public class ExceptionDemo2 { public static void main(String[] args) { // TODO Auto-generated method ...

  2. 学习笔记之TensorFlow

    TensorFlow https://www.tensorflow.org/ An open source machine learning framework for everyone Tensor ...

  3. 给VMware下的Linux扩容磁盘空间到根分区(以centos7.0为例)

    一.扩展VMWare硬盘空间 关闭Vmware 的 Linux系统,这样,才能在VMWare菜单中设置: VM -> Settings... -> Hardware -> Hard ...

  4. Eclipse使用Maven创建Web时错误:Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webap

    网上也有好多方法我没有试成功,不过我将maven的conf setting.xml里的 阿里镜像给注释就可以了,你们也可以试试

  5. logstash报错401 需要在logstash启动的配置文件中增加es的用户名和密码

  6. 谷歌获取chromium

    转自:http://blog.sina.com.cn/s/blog_496be0db0102voit.html 先参看 http://www.chromium.org/developers/how-t ...

  7. ip route rule 路由策略 高级路由 捆绑 网桥

    http://lwfs.net/2005/11/28/10/ #!/bin/bash IP0= IP1= GW0= GW1= NET0= NET1= DEV0=eth0 DEV1=eth1 # com ...

  8. MFC+mongodb+nodejs 数据库的读取与写入操作

    首先通过nodejs和mongodb建立后端服务器 一.在windows平台下启动mongodb服务器 1.进入mongodb的安装目录,并进去bin目录启动mongod 2.在d盘建立mongodb ...

  9. c#语言函数

    class Program {访问修饰符 函数名(参数1,参数2){   函数体   return 返回值} 无参数,无返回值 public static void abc()             ...

  10. MPEG-1视屏压缩标准

    MPEG-1标准包括5个部分 图像的四种类型: I帧: B帧:双向帧间预测 P帧: D帧:只含有16分量,为快放设计 压缩前需要帧重排 视屏码流结构 I帧压缩 p帧压缩 b帧压缩 其他压缩算法 MPE ...