1、HttpResponse()
def year_n(request,month,year): return HttpResponse("<html><body><h1>%s年%s月</h1></body></html>"%(str(year),str(month)))
return render(request,"register.html",locals()) return render_to_response("register.html",locals())
3、locals() 传views.py的所有参数到前端,通过变量名与前端对应,字典类型
return render(request,"register.html",{"p":p,"t":t}) return render(request,"register.html",locals())
4、redirect() 重定向页面,与render()方法有两个区别
4.1、render方法,url没有完全跳转,重新刷新地址栏后会返回到原url
4.2、render方法,可以传值到要跳转的页面,redirect方法不能直接传值到要跳转的页面,
def login(request): if request.method == "POST": u = request.POST.get("user",None) return render(request,"index.html",locals()) #render方法 return redirect('dis_index') #redirect方法,重定向到urls后于url的name字段匹配