Skip to main content

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

flask_optional_routes-1.4.1.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

flask_optional_routes-1.4.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file flask_optional_routes-1.4.1.tar.gz.

File metadata

  • Download URL: flask_optional_routes-1.4.1.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.13

File hashes

Hashes for flask_optional_routes-1.4.1.tar.gz
Algorithm Hash digest
SHA256 20030f7792eb00963baa8c24d02cc79a10d536e79603983df8c96fccce735f7c
MD5 8e47417e7cb1708184593786672ba724
BLAKE2b-256 0e32f709b6115a690b3f336f0f954cfc8a9823eaa526b0897685bd18166fe98a

See more details on using hashes here.

File details

Details for the file flask_optional_routes-1.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_optional_routes-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 67b1cf4aaac2b9d2b768ba95060f51ea5fc10bfccd3ec84b931ce6568dcc4f51
MD5 ea94c2f4ef7799b2c5d94e9d9cd41640
BLAKE2b-256 2ef7512eb5e345111c34dfe3b8eaf65c0dea806f2df5e4577808af3d7b33b3b3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page