render函数和redirect函数

1.get方法和post方法一样 通过request.get request.post获取

urls文件内容

urlpatterns = [
    # get发送数据
    url(r"sendByget", views.sendByget),
]


views文件内容:

def sendByget(request):
    print(".....>>>", request.GET)
    return HttpResponse("ok")


网页内容

<a href="/app01/sendByget/?year=207&month=12">发送a>

2.

render函数可以传三个参数  locals传递变量给页面  
def back(request):
    name='xp'
    return render(request,"back.html",locals())
 
  
back.html内容 通过双大括号获取
 
  
<h1>hello {{name}}h1>

3.request函数  跳转使用
from django.shortcuts import render, HttpResponse,redirect

def login_in(request):
    if request.method == "POST":
        # print("=====>", request.POST)
        username = request.POST.get("user")
        password = request.POST.get("pwd")
        if username == "yuan" and password == "123":
            return redirect("/back")
    return render(request, "lgoin_in.html")


你可能感兴趣的:(Python,web框架)