• Web接口开发与自动化测试


    def login_action(request):
    if request.method == 'POST':
    username = request.POST.get('username','')
    password = request.POST.get('password','')
    user = auth.authenticate(username=username,password=password)
    if user is not None:
    auth.login(request,user)
           # 登录保存session
    request.session['user'] = username
    response = HttpResponseRedirect('/event_manage/')
           # 设置cookie,3600为保持时间,默认为秒
           response.set_cookie('user',username,3600)
    return response
    else:
    return render(request, 'index.html', {'error':'账号或密码错误!'})



    # 获取浏览器session
    username = request.session.get('user','')

    # 获取浏览器cookies
    username = request.COOKIES.get('user','')

    此外还需要创建django_session表,存放用户session_id

    cmd.exe执行以下命令:

    python manage.py migrate

  • 相关阅读:
    js操作
    函数知识点补充
    css---position
    css-浮动
    css-边界重叠以及边界塌陷
    css
    css文本类型操作
    POJ 2828 线段树活用
    POJ 3468 线段树
    POJ 3013 SPFA算法,邻接表的使用
  • 原文地址:https://www.cnblogs.com/Tester_Dolores/p/11888666.html
Copyright © 2020-2023  润新知