python USES get_argument to get the url query parameter

  • 2020-05-30 20:31:48
  • OfStack

python USES get_argument to get the url query parameter

Each request handler of ornado, we call it handler, and in handler you can customize your own handler, which is essentially an override method, post, get, get_current_user, send_error, and so on. We're just talking about the customizations of get and post.

As we all know, in Tornado, when you get input from the user, it's all 1 get_argument, which seems like a logical thing to do:

def post(self):
	nowamagic = self.get_argument('nowamagic')
	self.write( nowamagic )

Let's start with a few basics. Let's take a look at this one URL: http: / / www nowamagic. net/academy/detail / 13321002 & # 63; page = 1 # comment

>>> import urlparse
>>> urlparse.urlparse('')
ParseResult(scheme='http', netloc='', path='/academy/detail/13321002', params='', query='page=1', fragment='comment')

url consists of scheme(protocol), netloc (host), path (path), params (parameter of the last path), query (query field), fragment (anchor).

Now, what if we want to get the GET parameter in URL, which is url query?

For the value of single 1, self.get_argument ("name", "default") is called in get and post.

For a multi-choice value, call self.get_arguments ("name").

The get_argument method can set the default value or whether to remove Spaces at both ends.

The source declaration is as follows:

get_argument(self, name, default=_ARG_DEFAULT, strip=True)
get_arguments(self, name, strip=True)

Thank you for reading, I hope to help you, thank you for your support of this site!

Related articles: