Skip to content

Instantly share code, notes, and snippets.

@hodgesmr
hodgesmr / hijacking_flask_routing_for_fun_and_profit.py
Last active June 18, 2024 15:22
Automatically register Flask routes with and without trailing slash. This way you avoid the 301 redirects and don't have to muddy up your blueprint with redundant rules.
"""Flask Blueprint sublcass that overrides `route`.
Automatically adds rules for endpoints with and without trailing slash.
"""
from flask import Blueprint, Flask
class BaseBlueprint(Blueprint):
"""The Flask Blueprint subclass."""