Quickstart

Minimal application

A minimal Broadway application looks something like this:

import broadway

factory = broadway.factory()

app = factory(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

Save this as app.py, and run the the server using the flask command line.

$ export WSGI_APP=app.py
$ flask run
* Serving Flask app "app"
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

If you head to http://127.0.0.1:5000/ now you should a response.

Simple application

A more advanced application will have views and models, split across different modules.

Instead of creating an application, we define a factory in the root of our python package.

# myapp/__init__.py
import broadway

factory = broadway.factory()

factory.add_extensions(
    'broadway.errors',
    'broadway.whitenoise',
)

factory.add_blueprints(
    'myapp.views:blueprint',
)

Associate any views with a Blueprint. Which we have told our factory to load in the above add_blueprints() call.

# myapp/views.py
import flask

blueprint = flask.Blueprint('main', __name__)

@blueprint.route('/')
def hello_world():
    return 'Hello World!'

@blueprint.route('/error')
def error():
    flask.abort(500)

We define a template for the error page.

{# myapp/templates/errors/500.html #}
<html>
  <head>
    <title>Server Error</title>
  </head>
  <body>
    <h1>Server Error</h1>
  </body>
</html>

And finally we create a WSGI file to run our application.

# wsgi.py
import myapp

application = myapp.factory('myapp')

Save this as wsgi.py, and run the the server using the flask command line.

$ export WSGI_APP=wsgi.py
$ flask run
* Serving Flask app "myapp"
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

If you head to http://127.0.0.1:5000/error now you should a templated response.