defernia.web — Web frontend

Defernia uses Flask as framework for web frontend. It depends on Werkzeug and Jinja2 also.

See also

Module defernia.web.routing
Extended Werkzeug routing converters for Defernia.
Blueprint defernia.web.home
Website home.
Blueprint defernia.web.user
User authentications, personal pages, and so on.
Module defernia.web.helpers
Helpful template filters, tests and functions for Jinja.
Module defernia.web.serializers
Object serializers for various content types.
Module defernia.web.wsgi
Custom WSGI middlewares for Defernia web application.
flask.g.world_repodir

(defernia.world.repo.RepositoryDirectory) The global variable that stores the world repository directory object.

flask.g.session

(defernia.orm.Session) The global variable that stores the SQLAlchemy session.

flask.g.database_engine

(sqlalchemy.engine.base.Engine) The global variable that stores SQLAlchemy dtabase engine.

defernia.web.blueprints = {'defernia.web.user:user': {'url_prefix': '/users'}, 'defernia.web.world:world': {'url_prefix': '/worlds'}, 'defernia.web.home:home': {}}

The dict of blueprints to be registered. Keys are import names in string, and values are keyword arguments for flask.Flask.register_blueprint() method.

blueprints = {'module.name:var': {'url_prefix': '/path'},
              'module.name2:var2': {}}

See also

Function werkzeug.utils.import_string()
The function that imports an object based on a string, provided by Werkzeug.
Flask — Modular Applications with Blueprints
Flask provides ‘blueprint’ facilities for large applications.
defernia.web.wsgi_middlewares = ['defernia.web.wsgi:MethodRewriteMiddleware']

The list of WSGI middlewares to hook in. Its elements are import names in string.

wsgi_middlewares = ['defernia.web.wsgi:MethodRewriteMiddleware']

See also

Function werkzeug.utils.import_string()
The function that imports an object based on a string, provided by Werkzeug.
Module defernia.web.wsgi
Custom WSGI middlewares for Defernia web application.
Flask — Hooking in WSGI Middlewares
Flask provides a way to hook in WSGI middlewares.
defernia.web.content_types = {'text/xml': '.xml', 'text/html': '.html', 'application/xhtml+xml': '.html', 'application/plist+xml': 'defernia.web.serializers:to_plist', 'application/json': 'defernia.web.serializers:to_json', 'application/x-plist': 'defernia.web.serializers:to_plist'}

The dict of serializers for content types. Keys are MIME types like application/json, and values are functions that encode a value into the paired type, or a string which is a postfix of the template filename e.g. '.html', '.xml'. If value is a string that doesn’t start with period (.), it will be interpreted as import name.

content_types = {'application/json': json.dumps,
                 'text/yaml': 'defernia.web.serializers:yaml',
                 'text/html': '.html',
                 'text/xml': '.xml'}

See also

Function render()
The generic content type version of flask.render_template().
Function werkzeug.utils.import_string()
The function that imports an object based on a string, provided by Werkzeug.
defernia.web.create_app(modifier=None, config_filename=None)

An application factory. It sets up the application then returns the application.

app = create_app(config_filename='prod.cfg')

Instead you pass an argument config_filename, it can be used as decorator-style as well:

@create_app
def app(app):
    app.debug = True
    app.config['MAGIC_NUMBER'] = 1234
Parameters:
  • modifier (callable object) – a function, for decorator-style use
  • config_filename (basestring) – a configuration file name
Returns:

a WSGI application

Return type:

flask.Flask

defernia.web.get_world_repodir(config)

Gets defernia.world.repo.RepositoryDirectory object from the config.

Parameters:config (flask.Config, dict) – the configuration that contains 'REPODIR_PATH'
Returns:world repository directory object
Return type:defernia.world.repo.RepositoryDirectory
defernia.web.get_database_engine(config)

Gets SQLAlchemy Engine object from the config.

Parameters:config (flask.Config, dict) – the configuration that contains 'DATABASE_URL' or 'ENGINE'
Returns:SQLAlchemy database engine
Return type:sqlalchemy.engine.base.Engine

See also

SQLAlchemy — Engine Configuration

defernia.web.before_request(function)

The decorator that registers function into before_request_funcs.

defernia.web.after_request(function)

The decorator that registers function into after_request_funcs.

defernia.web.define_session()

Sets the g.world_repodir, g.session and g.database_engine global variables before every request.

defernia.web.render(template_name, value, **context)

The generic content type version of flask.render_template() function. Unlike flask.render_template(), it takes one more required parameter, value, for generic serialization to JSON-like formats. And template_name doesn’t include its postfix.

render('user/profile', user, user=user)
Parameters:
  • template_name (basestring) – the name of the template to be rendered, but postfix excluded
  • **context – the variables that should be available in the context of the template

See also

Constant content_types

Project Versions

Previous topic

defernia.objsimplify — Object simplifier for generic serialization

Next topic

defernia.web.routing — Custom routing converters

This Page