Flask-Reggie
Enable Regex Routes within Flask
Installation
pip install flask-reggie
Configuration
To enable regex routes within your application
from flask import Flask
from flask_reggie import Reggie
app = Flask(__name__)
Reggie(app)
or
from flask import Flask
from flask_reggie import Reggie
reggie = Reggie()
def create_app():
app = Flask(__name__)
reggie.init_app(app)
return app
Usage
If we were looking to have a UUID supplied as a view argument, we would follow this pattern
@app.route('/<regex("[0-9a-f]{32}"):uuid>')
def example(uuid):
return uuid
As you can see, we are able to supply a regular expression, and have it passed as a view argument.
Simple.