请求与响应
转递数据与接收
三个请求方式
三个响应方式
def req_list(request): # 请求1 # print(request.method) # m1 = request.method # 请求2 # print(request.GET) # m2 = request.GET # 请求3 # print(request.POST) # m3 = request.POST # 响应1 # return HttpResponse("返回内容") # 响应2 读取HTML内容,+ 渲染(替换) # return render(request, 'req_list.html', {"m1": m1, "m2": m2, "m3": m3}) # 响应3 重新定向 return redirect("https://www.baidu.com")
例:登录
def login(request): if request.method == 'GET': return render(request, 'login.html') else: print(request.POST) name = request.POST.get('username') password =request.POST.get('password') if name == 'admin' and password == '123456': # return HttpResponse("登录成功") return redirect('https://wwww.baidu.com') else: return render(request, 'login.html', {'error_message':'用户名或者密码错误'})
标签:return,请求,request,django,响应,print,POST From: https://www.cnblogs.com/luckylu/p/17369036.html