Luke Ross

Scripts

6 commits git clone

Small scripts

0eab2e2cfe760b3b1114bff9f8fba5fd3c464ce9 / Werkzeug-FormatStringRouting /

werkzeug_formatstringrouting/
LICENSE new package: Werkzeug-FormatStringRouting 19 Feb 2019
README.md new package: Werkzeug-FormatStringRouting 19 Feb 2019
setup.py new package: Werkzeug-FormatStringRouting 19 Feb 2019

README.md

# Werkzeug-FormatStringRoutig

This is a replacement for werkzeug.routing.Rule which uses str.format()-style
routing patterns.

Instead of:

```
@app.route('/topics/<topic>/edit/<int:n>')
```

...you can use:

```
@app.route('/topics/{topic}/edit/{id:n}')
```

## Using with Flask

Subclass Flask and in your subclass you can instruct Flask to use the
alternative Rule. Once done, you can instantiate it as normal:

```
from flask import Flask
from werkzeug_formatstringrouting import Rule


class CustomisedFlask(Flask):
    url_rule_class = Rule


# Use CustomisedFlask where you would use Flask
app = CustomisedFlask(__name__)
```

## Quirks & Limitations

- Matches without a type (eg. `{name}`) will not match anything containing
  slashes, similar to how Werkzeug matches strings.

- To match paths, use the `path` type: `{my_path:path}`.

- For more details on how the matching is handled and the types available,
  please see the documentation for the `parse` library.

- Use of the `redirect_to` parameter is not supported, because of how Werkzeug
  builds the target URL to redirect to.

## License

Issued under the same license as Werkzeug. Please see the LICENSE file for
more details.

## Author

Luke Ross <lr@lukeross.name>