defernia.web.routing — Custom routing converters

See also

Werkzeug — URL Routing

class defernia.web.routing.CredentialTypeConverter(map)

Bases: werkzeug.routing.BaseConverter

This converter accepts Credential types, represented in typeid string:

Parameters:map (werkzeug.routing.Map) – the Map
exception defernia.web.routing.MovedPermanently(url, description=None)

Bases: werkzeug.exceptions.HTTPException

301 Moved Permanently

url = None

The URL to redirect.

class defernia.web.routing.UserConverter(map, autoredirect=True)

Bases: werkzeug.routing.BaseConverter

This converter accepts User objects, represented in id with optional slug generated from name. For example:


Actually it does not returns a User object. Instead, it returns a function that returns a User object. So you have to call after give it:

def profile(user):
    user = user()
  • map (werkzeug.routing.Map) – the Map
  • autoredirect (bool) – whether redirects the user to the canonical url when the request url is not canonical


It has a lot of side effects about errors and redirections that are unexpected in the design of werkzeug.routing.BaseConverter class. Please be careful!

autoredirect = True

Whether redirects the user to the canonical url when the request url is not canonical.


Makes a normalized slug for the user.

defernia.web.routing.converters = {'credtype': <class 'defernia.web.routing.CredentialTypeConverter'>, 'user': <class 'defernia.web.routing.UserConverter'>}

The dictionary of extended routing converters. It should be registered when the Flask application has created:

app = flask.Flask(__name__)

See also

Attribute flask.Flask.url_map

Project Versions

Previous topic

defernia.web — Web frontend

Next topic

defernia.web.home — Website home

This Page