Skip to main content

Flask-Via adds a cleaner method for defining routes to your Flask views, inspired by Django urls.

Project description

Inspired by the Django URL configuration system, Flask-Via is designed to add similar functionality to Flask applications which have grown beyond a simple single file application.

Travis build status on Master Branch Test Coverage Code Health Latest PyPI version Number of PyPI downloads MIT License

Example

from flask import Flask
from flask.ext.via import Via
from flask.ext.via.routers.default import Basic

app = Flask(__name__)

def foo(bar=None):
    return 'Foo View!'

routes = [
    Basic('/foo', foo),
    Basic('/foo/<bar>', foo, endpoint='foo2'),
]

via = Via()
via.init_app(app, route_module='flask_via.examples.basic')

if __name__ == "__main__":
    app.run(debug=True)

Why?

Growing your application can be quite difficult when it’s not always clear where and how your routes are discovered. This can lead to a cluttered application factory method when all your routes are defined at application creation - resulting in code which is difficult to maintain, not to mention messy.

A better solution is to define your routes in a routes.py and automatically load them at application start up. This is what Flask-Via helps to do.

Third party Flask extensions don’t always follow the same conventions for adding routes to an application, so Flask-Via has been designed to be easy for developers to write their own custom routers. For an example of this, take a look at the bundled Flask-Restful Resource router.

If you do write a custom router that is useful to you, it will probably be useful to someone else so please do contribute back :)

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-Via-2014.05.08.tar.gz (10.8 kB view details)

Uploaded Source

File details

Details for the file Flask-Via-2014.05.08.tar.gz.

File metadata

File hashes

Hashes for Flask-Via-2014.05.08.tar.gz
Algorithm Hash digest
SHA256 6244a79998c37a142dac4aa5c19501a5459d2f6221fa8520f4d351bf4e841f81
MD5 6f20c8b79f4c8466832bafbdedb59097
BLAKE2b-256 f381a37f7605efe02a63ffce289c5d5bbbb2761247a01c11835620e553a47866

See more details on using hashes here.

Supported by

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