Django请求的生命周期是指:当用户在访问该url路径是,在服务器Django后台都发生了什么。

客户端发送Http请求给服务端,Http请求是一堆字符串,其内容是:python---django请求-响应的生命周期(FBV和CBV含义)

访问:http://crm.oldboy.com:8080/login.html,客户端发送Http请求

1.路由映射,匹配路由(从上到下,匹配到就停止),对应相应views中的业务函数

url(r'^login.html', views.login),

2.匹配成功后,执行views下的对应函数:(FBV)

def login(req):
    print('req.body',req.body)
    print("GET",req.GET)
    message=''
    if req.method == "POST":
        print(req.body)
        print(req.POST)

        user = req.POST.get("username")
        pwd = req.POST.get("password")

        count = models.Administrator.objects.filter(username=user,password=pwd).count()
        if count:
            red = redirect("/index.html")
            timeout = datetime.datetime.now()+datetime.timedelta(seconds=3)
            red.set_cookie('username',user,expires=timeout)
            return red
        else:
            message = "用户名或密码错误"
    return render(req,"login.html",{'msg':message})
View Code

相关文章:

  • 2021-11-23
  • 2022-02-23
  • 2021-10-14
  • 2022-12-23
  • 2022-12-23
  • 2021-06-09
  • 2021-06-24
猜你喜欢
  • 2021-09-01
  • 2021-06-26
  • 2022-12-23
  • 2021-10-12
  • 2021-08-03
  • 2021-06-15
  • 2021-11-18
相关资源
相似解决方案