Django请求的生命周期是指:当用户在访问该url路径是,在服务器Django后台都发生了什么。
客户端发送Http请求给服务端,Http请求是一堆字符串,其内容是:
访问: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})