馃崻 Cookies in Flask 馃嵕

ketanip

KetanIP

Posted on October 13, 2020

馃崻 Cookies in Flask 馃嵕

What are cookies ?

Cookies are a kind of storage, but a very small storage. It is mainly used to store small information such as csrf_token, login credentials ( encrypeted ), preferences, site statics and/or user activities. By using cookies one can provide an immersive experice to the users of the websites by making the website more personalized for them.

How to use "Cookies" in Flask ?

In flask using cookies is super simple. In flask cookies are Immutable Dictionary, we can also call as a dictionary. To view the value of the request.cookies attribute it will return an dictionary object. Let's see an understand it with an example,

app.py

from flask import Flask, request, make_response, redirect, url_for, render_template

app = Flask(__name__)

@app.route("/")
def home():
    userName = request.cookies.get("name")
    if userName:
        return f"Hello {userName}." 
    else:
        return redirect(url_for("setName"))
Enter fullscreen mode Exit fullscreen mode

Continue reading here 馃崻 Cookies in Flask 馃嵕.

馃挅 馃挭 馃檯 馃毄
ketanip
KetanIP

Posted on October 13, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related