Quickstart

Installation

Flask-Via is simple to install, just use your favourite python package manage, for example pip:

$ pip install Flask-Via

Basic Application

Once we have installed Flask-Via we need to perform the following steps:

  1. Create some view functions
  2. Create a list of routes
  3. Initialise flask_via.Via and call flask_via.Via.init_app()

The following example code performs the above steps with key lines emphasised.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
from flask import Flask
from flask.ext.via import Via
from flask.ext.via.routers.default import Functional

app = Flask(__name__)

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

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

via = Via()
via.init_app(app, route_module='path.to.here')

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

Lines 10-13 show how routes are defined in a list using the basic flask router class (flask_via.routers.default.Functional).

Line 16 shows how we Flask-Via looks for where routes are defined, this can be set as we have done above or using the VIA_ROUTES_MODULE application configuration variable.

http://thisissoon.com

Table Of Contents

Related Topics

This Page