Skip to content Skip to sidebar Skip to footer

What Does Request.get.get Mean?

Solution 2:

request.GET is the dictionary of the GET variables in the http request made to your server for example:

www.google.com?thisIsAGetVarKey=3&thisIsAnotherOne=hello

request.GET would be: {"thisIsAGetVarKey": 3, "thisIsAnotherOne":"hello"}

Because request.GET is a dictionary, it has the method .get() which retrieves a value for a key in the dictionary

dict_b = {'number': 8, 'alphabet':'A'}
print dict_a['number'] #prints 8print dict_a.get('alphabet') #prints Aprint dict_a['bob'] #throws KeyErrorprint dict_a.get('bob') #prints Noneprint dict_a.get('bob', default=8) #prints 8

Solution 3:

request.GET is the dictionary of the 'GET' variables in the http request made to your server for example: www.google.com?thisIsAGetVarKey=3&thisIsAnotherOne=hello

request.GET would be: {"thisIsAGetVarKey": 3, "thisIsAnotherOne":"hello"}

Because request.GET is a dictionary, it has the method .get() which retrieves a value for a key in the dictionary -

dict_a = {'age': 3}
print dict_a['age'] #prints 3print dict_a.get('a') #also prints 3print dict_a['hello'] #throws KeyErrorprint dict_a.get('hello') #prints Noneprint dict_a.get('hello', default=3) #prints 3

Post a Comment for "What Does Request.get.get Mean?"