Sessions in Flask
In Session, the data is stored on Server. It can be defined as a time interval in which the client logs into a server until the user logs out. The data in between them are held in a temporary folder on the Server. Each user is assigned with a specific
Session ID
The Session object is a dictionary that contains the key-value pair of the variables associated with the session. A SECRET_KEY is used to store the encrypted data on the cookie.
Example
Session[key] = value // stores the session value
Session.pop(key, None) // releases a session variable
Other Important Flask Functions
redirect
It is used to return the response of an object and redirects the user to another target location with specified status code.
Syntax: Flask.redirect(location, statuscode, response)
//location is used to redirect to the desired URL //statuscode sends header value, default 302 //response is used to initiate response.
abort
It is used to handle the error in the code.
Syntax: Flask.abort(code)
The code parameter can take the following values to handle the error accordingly:
- 400 – For Bad Request
- 401 – For Unauthenticated
- 403 – For Forbidden request
- 404 – For Not Found
- 406 – For Not acceptable
- 425 – For Unsupported Media
- 429 – Too many Requests
Introduction to Web development using Flask
Flask is a lightweight and flexible web framework for Python. It’s designed to make getting started with web development quick and easy, while still being powerful enough to build complex web applications. Let’s understand Flask Python in more Detail