zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    睁大你的眼睛,警惕职业生涯中的“红灯”
    几则好玩的脑筋急转弯
    File.Delete()的解决
    Powershell之True或False
    发送邮件
    IE与CSS兼容性
    WSS
    File.Delete()
    添加field部署
    css加载
  • 原文地址:https://www.cnblogs.com/Tester_Dolores/p/11888666.html
Copyright © 2011-2022 走看看