Post / get request

Started by nicolebeckett, Feb 02, 2023, 04:41 AM

Previous topic - Next topic

nicolebeckettTopic starter

I've started my journey to learn Python and everything was going well until I faced a problem - how can I accept requests in a script? In PHP, it's done by using $_POST['lalala'] for POST requests and $_GET['lalala'] for GET requests. However, I'm not sure how to do it in Python. I've been told that the requests module is needed and have downloaded and installed it on my hosting. I've managed to learn how to send requests using the module, but I'm still unable to find any information on how to receive requests.

I've discovered that using the line 'attat =', I can accept the query string, which will be equal to attat. However, it's not very convenient. Is there a Python solution similar to the one in PHP for accepting POST requests? As for GET requests, I'm not sure what to do at all.


HTTP clients send HTTP requests and there is a library called 'requests' that can help in creating an HTTP client.

When an HTTP request, such as GET/POST, is made, it is answered by an HTTP server (such as Apache, Nginx, or Gunicorn) which can run Python code using CGI or WSGI interfaces. In Python, there are several web frameworks such as Bottle, Flask, Pyramid, and Django that provide a higher-level interface for developing web applications. Additionally, there are also more general network libraries like Twisted, Tornado, and Gevent.


It might be worth looking into some web frameworks such as Bottle, Flask, or Django.

When using the GET or POST form method, you can print the username using the following code:
print request.GET['username'] # for GET form method
print request.POST['username'] # for POST form method