How are POST and GET variables handled in Python?

前端 未结 6 614
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 11:59

In PHP you can just use $_POST for POST and $_GET for GET (Query string) variables. What\'s the equivalent in Python?

6条回答
  •  [愿得一人]
    2020-11-22 12:18

    I've found nosklo's answer very extensive and useful! For those, like myself, who might find accessing the raw request data directly also useful, I would like to add the way to do that:

    import os, sys
    
    # the query string, which contains the raw GET data
    # (For example, for http://example.com/myscript.py?a=b&c=d&e
    # this is "a=b&c=d&e")
    os.getenv("QUERY_STRING")
    
    # the raw POST data
    sys.stdin.read()
    

提交回复
热议问题