Bootstrap FreeKB - Flask - Session Domain
Flask - Session Domain

Updated:   |  Flask articles

This assumes you are already familiar with Flask Sessions. If not, check out my article FreeKB - Flask - Getting Started with Sessions.

By default, the session domain should be the SERVER_NAME of your Flask app. For example, if you website domain is example.com then the session domain should be example.com which you can see in Edge at edge://settings/content/cookies/siteData.

 

SESSION_COOKIE_DOMAIN can be set in __init__.py. In this example, the session domain is set to 127.0.0.1, the hostname when running Flask in VSCode.

from flask import Flask
from datetime import timedelta

def myapp():
    app = Flask(__name__)
    
    app.config['SECRET_KEY'] = "akDFJ34mdfsYMH567sdf" # this must be set in order to use sessions
    
    app.config['SESSION_COOKIE_DOMAIN'] = '127.0.0.1'

    return app

 

You may want to also run Flask in debug mode so you get additional logging to better understand what Flask is doing.

from myapp import app

app = app()

if __name__ == "__main__":
    app.run(debug=True)

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 81c903 in the box below so that we can be sure you are a human.