Junior — Middle
Could you explain what is meant by URL query parameters?
sobes.tech AI
Answer from AI
URL query parameters are the part of the address after the question mark (?) that transmits additional data to the server.
For example, in the URL:
https://example.com/search?q=python&sort=asc
query parameters are q=python and sort=asc.
They consist of key=value pairs, separated by an ampersand (&). The server or application can use these parameters for filtering, searching, sorting, and other operations.
In Python, you can work with query parameters using the urllib.parse module:
from urllib.parse import urlparse, parse_qs
url = 'https://example.com/search?q=python&sort=asc'
parsed_url = urlparse(url)
params = parse_qs(parsed_url.query)
print(params) # {'q': ['python'], 'sort': ['asc']}
Thus, query parameters allow for dynamically passing data through the URL.