Skip to main content

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/

Metadata

Release files for flask-optional-routes 1.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flask-optional-routes 1.4.1
File Size Uploaded
flask_optional_routes-1.4.1.tar.gz 3.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flask-optional-routes 1.4.1
File Interpreter ABI Platform
flask_optional_routes-1.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 7.2 kB

Release files / flask_optional_routes-1.4.1.tar.gz

Download URL flask_optional_routes-1.4.1.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
20030f7792eb00963baa8c24d02cc79a10d536e79603983df8c96fccce735f7c
BLAKE2b-256 checksum
How to use checksums
0e32f709b6115a690b3f336f0f954cfc8a9823eaa526b0897685bd18166fe98a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.13

Release files / flask_optional_routes-1.4.1-py3-none-any.whl

Download URL flask_optional_routes-1.4.1-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
67b1cf4aaac2b9d2b768ba95060f51ea5fc10bfccd3ec84b931ce6568dcc4f51
BLAKE2b-256 checksum
How to use checksums
2ef7512eb5e345111c34dfe3b8eaf65c0dea806f2df5e4577808af3d7b33b3b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.13

Release history Release notifications | RSS feed

This release

1.4.1 This release

2 release files

1.4

2 release files

1.3

1 release file

1.2

1 release file

1.1

1 release file

1.0

1 release file

0.9

1 release file

0.8

1 release file

0.7

1 release file

0.6

1 release file

0.5

1 release file

0.4

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page