Python的web框架Django的Request,META(7)

Request

我们可以看到,接收参数的方法时,我们都会在前面加入一个request,这个request有一些属性供我们取用

def getMoreEl(request,nonum,age,sex):

    content = {
                "path":request.path,
                "method":request.method,
                "encoding":request.encoding,
                "get":request.GET,
                "post":request.POST,
                "files":request.FILES,
                "cookies":request.COOKIES,
                #"session":request.session
                "is_ajax()":request.is_ajax()
              }

    return HttpResponse(json.dumps(content))

请求结果

我们可以尝试用路径传一下参数,看看get中有没有

http://127.0.0.1:8000/two/getParam/?name=抽风&&age=99&&birthday=1991-12-24

 

 Post同理,也可以在Post中取到

Reuqest的META方法

这个方法包含了很多参数,比如可能用到的请求IP,浏览器等等

print(request.META)

目测里面还有环境变量。。。。。

发布了143 篇原创文章 · 获赞 255 · 访问量 18万+

猜你喜欢

转载自blog.csdn.net/jiulanhao/article/details/103583173
今日推荐