Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is "from flask import request" identical to "import requests"?

Tags:

In other words, is the flask request class identical to the requests library?

I consulted:

http://flask.pocoo.org/docs/0.11/api/

http://docs.python-requests.org/en/master/

but cannot tell for sure. I see code examples where people seem to use them interchangeably.

like image 763
Fred Zimmerman Avatar asked Sep 04 '16 16:09

Fred Zimmerman


People also ask

What is from Flask import request?

The Flask request object contains the data that the client (eg a browser) has sent to your app - ie the URL parameters, any POST data, etc. The requests library is for your app to make HTTP request to other sites, usually APIs. It makes an outgoing request and returns the response from the external site.

What is from Flask import Flask?

Flask is the framework here, while Flask is a Python class datatype. In other words, Flask is the prototype used to create instances of web application or web applications if you want to put it simple. So, once we import Flask, we need to create an instance of the Flask class for our web app.

What does import requests mean in Python?

Definition and Usage The requests module allows you to send HTTP requests using Python. The HTTP request returns a Response Object with all the response data (content, encoding, status, etc).

How does request work in Flask?

When the Flask application handles a request, it creates a Request object based on the environment it received from the WSGI server. Because a worker (thread, process, or coroutine depending on the server) handles only one request at a time, the request data can be considered global to that worker during that request.


1 Answers

No these are not only completely different libraries, but completely different purposes.

Flask is a web framework which clients make requests to. The Flask request object contains the data that the client (eg a browser) has sent to your app - ie the URL parameters, any POST data, etc.

The requests library is for your app to make HTTP request to other sites, usually APIs. It makes an outgoing request and returns the response from the external site.

like image 180
Daniel Roseman Avatar answered Sep 18 '22 12:09

Daniel Roseman