Bases: object
Handles the import of routes module and obtaining a list of routes from that module as well as loading each route onto the application
Imports a routes module and gets the routes from within that module and returns them.
Parameters: |
|
---|---|
Returns: | List of routes in the module |
Return type: | list |
Bases: flask_via.RoutesImporter
The core class which kicks off the whole registration processes.
Example
from flask import Flask
from flask.ext.via import Via
from flask.ext.via.routers.flask 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, routes_module='path.to.here')
if __name__ == "__main__":
app.run(debug=True)
Initialises Flask extension. Bootstraps the automatic route registration process.
Parameters: | app (flask.app.Flask) – Flask application instance |
---|---|
Keyword Arguments: | |
|
|
Raises: |
|
Base router classes and utilities.
Bases: object
Base router class all routers should inherit from providing common router functionality.
Example
from flask.ext.via.routers import BaseRouter
class MyRouter(BaseRouter):
def __init__(self, arg):
...
def add_to_app(self, app):
...
Bases: flask_via.routers.BaseRouter, flask_via.RoutesImporter
Adds the ability to include routes from other modules, this can be handy when you want to break out your routes into separate files for sanity.
Note
This is not a implementation of Flask blueprints
Constructor for Include router, taking the passed arguments and storing them on the instance.
Parameters: | routes_module (str) – Python dotted path to the routes module |
---|---|
Keyword Arguments: | |
routes_name (str (optional)) – Name of the variable holding the routes in the module, defaults to routes |
Instead of adding a route to the flask application this will include and load routes similar, same as in the flask_via.Via class.abs
Parameters: |
|
---|
A set of flask specific router classes to be used when defining routes.
Example
from flask.ext.via.routes.flask import Basic, Pluggable
from yourapp.views import BarView, foo_view
routes = [
Basic('/foo', 'foo', foo_view),
Pluggable('/bar', view_func=BarView.as_view('bar')),
]
Bases: flask_via.routers.BaseRouter
A basic Flask router, used for the most basic form of flask routes, namely functionally based views which would normally use the @route decorator.
Example
from flask.ext.via.routes import flask
from yourapp.views import foo_view, bar_view
routes = [
Basic('/foo', 'foo', foo_view),
Basic('/bar', 'bar', bar_view),
]
Basic router constructor, stores passed arguments on the instance.
Parameters: |
|
---|---|
Keyword Arguments: | |
endpoint (str, optional) – Optional endpoint string, by default flask will use the view function name as the endpoint name, use this argument to change the endpoint name. |
Bases: flask_via.routers.BaseRouter, flask_via.RoutesImporter
Registers a flask blueprint and registers routes to that blueprint, similar to flask_via.routes.Include.
Example
from flask.ext.via.routers import default
routes = [
default.blueprint('foo', 'flask_via.examples.blueprints.foo')
]
Constructor for blueprint router.
Parameters: |
|
---|---|
Keyword Arguments: | |
|
Creates a Flask blueprint and registers routes with that blueprint, this means any routes defined will be added to the blueprint rather than the application.
Parameters: |
|
---|
Bases: flask_via.routers.BaseRouter
Pluggable View router class, allows Flask pluggable view routes to be added to the flask application.
Example
from flask.ext.via.routers import flask
from flask.views import MethodView
class FooView(MethodView):
def get(self):
return 'foo view'
class BarView(MethodView):
def get(self):
return 'bar view'
routes = [
flask.Pluggable('/', view_func=FooView.as_view('foo'))
flask.Pluggable('/', view_func=BarView.as_view('bar'))
]
Routers for the Flask-Restful framework.
Bases: flask_via.routers.BaseRouter
The Resource router allows you to define Flask-Restful routes and have those API resources added to the application automatically. For this to work you must at init_app time pass a optional keyword argument restful_api to init_app with its value being the restful api extension instance.
Example
app = Flask(__name__)
api = restful.Api(app)
class FooResource(restful.Resource):
def get(self):
return {'hello': 'world'}
routes = [
Resource('/foo', FooResource)
]
via = Via()
via.init_app(
app,
routes_module='flask_via.examples.restful',
restful_api=api)
if __name__ == '__main__':
app.run(debug=True)
Constructor for flask restful resource router.
Parameters: |
|
---|---|
Keyword Arguments: | |
endpoint (str, optional) – Optional, override Flask-Restful automatic endpoint naming |
Adds the restul api resource route to the application.
Parameters: | app (flask.app.Flask) – Flask application instance, this is ignored. |
---|---|
Keyword Arguments: | |
restful_api (str) – Instantiated restful API instace, used to add the route. | |
Raises: | NotImplementedError – If restful_api is not provided |