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:

Rule('/page/<credtype:service>')
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:

123
123/hong.minhee

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:

@app.route('/<user:user>')
def profile(user):
    user = user()
Parameters:
  • map (werkzeug.routing.Map) – the Map
  • autoredirect (bool) – whether redirects the user to the canonical url when the request url is not canonical

Warning

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.

slug(user)

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__)
app.url_map.converters.update(defernia.web.routing.converters)

See also

Attribute flask.Flask.url_map

Project Versions

Previous topic

defernia.web — Web frontend

Next topic

defernia.web.home — Website home

This Page