Jotting one man's journey through software development, programming, and technology
◀️ Home
In a simple project’s app.py:
app = Flask(__name__)@app.route(...)render_template, jsonify, or redirectBrowser (JS/HTML)
| HTTP request (GET /, POST /submit)
v
Flask route in app.py
| calls business logic (ConfigStore/modules)
v
Response (HTML / JSON / Redirect)
|
v
Browser renders UI or handles JSON
Mental model:
fetch).POST endpoints, JS often sends JSON payloads.request.get_json() (or request.json).jsonify(...); JS updates UI based on response.Typical shape:
if __name__ == "__main__":)In a simple app.py:
Flask, request, render_template, jsonify, redirect, url_for, session/login, /logout, /auth_callback, /, /submit)"/submit").GET = retrieve page/dataPOST = submit/change dataExample patterns for app.py:
@app.route("/login") -> return login HTML@app.route("/auth_callback", methods=["POST"]) -> process auth token@app.route("/submit", methods=["POST"]) -> accept form submission JSONCommon request sources:
request.args.get("message")request.get_json() or request.jsonsession["user_email"], session["next_url"]Common response types:
render_template("index.html", ...)jsonify({"status": "success"})redirect(url_for("login"))Session example in this app:
session.clear() resets user state.render_template("index.html", clients=..., employees=..., user_email=...)Rule of thumb:
Example repo:
app.py -> HTTP entrypoint and route definitionstemplates/ -> Jinja2 HTML templatesstatic/ -> CSS/JS/images served to browsermodules/ -> business logic and integrations (auth handlers, processors, etc.)config/ -> app configuration and object wiring (ConfigStore)Why this matters:
GET or POST.url_for: Flask helper to build URLs from endpoint names.A Flask Blueprint is a way to organize and structure a Flask application by grouping related routes, views, and other logic. It helps break a large application into smaller, modular components, making it easier to manage and maintain.
from flask import Blueprint
# Create a Blueprint instance
auth_bp = Blueprint('auth', __name__)
@auth_bp.route('/login')
def login():
return "Login Page"
@auth_bp.route('/logout')
def logout():
return "Logout Page"
# Register the Blueprint in the main app
from flask import Flask
app = Flask(__name__)
app.register_blueprint(auth_bp, url_prefix='/auth')
if __name__ == '__main__':
app.run()