This package allows you to specify optional routes in a url path
Project description
flask_optional_routes
This package allows you to specify optional routes in a url path.
How it works
Simply place a '?' delimiter at the end of a path segment and
this code will automatically add rules for all possible routes.
How to install
- Method 1: Use PIP
pip install flask_optional_routes
- Method 2:
Download from Github
Usage Example1
from flask import Flask
from flask_optional_routes import OptionalRoutes
app = Flask(__name__)
optional = OptionalRoutes(app)
@optional.routes('/<user_id>/<user_name>?/')
def foobar(user_id, user_name=None):
return 'it worked!'
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000)
Using @optional.routes('/<user_id>/<user_name>?/')
the following urls will show the same endpoint:
- /1/
- /1/john/
Usage Example2
from flask import Flask
from flask_optional_routes import OptionalRoutes
app = Flask(__name__)
optional = OptionalRoutes(app)
@optional.routes('/a/b?/c/d?/')
def foobar():
return 'it worked!'
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000)
Using @optional.routes('/a/b?/c/d?/')
the following urls will show the same endpoint:
- /a/c/
- /a/b/c/
- /a/c/d/
- /a/b/c/d/
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for flask_optional_routes-1.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ac09d042fd92a860c60623e5eadb7611d8d37a4793efe6e67e3deaf9d73ed80 |
|
MD5 | 6a9b46c7d1ba858de802f95066ebc929 |
|
BLAKE2b-256 | 8e2ccc561084d6d858773ca260357ecf0bb0348baf3356b4bfb06ff3d32cdd8c |
Close
Hashes for flask_optional_routes-1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 244fdfe3b3f32887f157e8345fbde267801dac3ecb6a28fb3fb4abe550d96103 |
|
MD5 | a7a4da2a47f2888e9ecde77bd2c841b9 |
|
BLAKE2b-256 | f11e0c5dd0f7e52dde86da6e7f5a63485349c66fe7281a11888d601cd777ca7e |