register_renderer(app, iid, renderer, force=True)[source]

Registers a renderer on the application.

Parameters:
  • app – The Flask application to register the renderer on

  • iid – Internal id-string for the renderer

  • renderer – Renderer to register

  • force – Whether or not to overwrite the renderer if a different one is already registered for iid

get_renderer(app, iid)[source]

Retrieve a renderer.

Parameters:
  • appFlask application to look iid up on

  • iid – Internal renderer id-string to look up

exception NavbarRenderingError[source]

Bases: Exception

The NavbarRenderingError class.

class ElementRegistry[source]

Bases: MutableMapping

The ElementRegistry class.

class Nav(app=None)[source]

Bases: object

The Flask-Nav extension.

Parameters:

app – An optional Flask app to initialize.

init_app(app)[source]

Initialize an application.

Parameters:

app – A Flask app.

navigation(iid=None)[source]

Function decorator for navbar registration.

Convenience function, calls register_element() with iid and the decorated function as elem.

Parameters:

iid – ID to pass on. If None, uses the decorated functions name.

register_element(iid, elem)[source]

Register navigational element.

Registers the given navigational element, making it available using the id iid.

This means that inside any template, the registered element will be available as nav. id.

If elem is callable, any attempt to retrieve it inside the template will instead result in elem being called and the result being returned.

Parameters:
  • iid – Id to register element with

  • elem – Element to register

renderer(iid=None, force=True)[source]

Class decorator for Renderers.

The decorated class will be added to the list of renderers kept by this instance that will be registered on the app upon app initialization.

Parameters:
  • iid – Id for the renderer, defaults to the class name in snake case.

  • force – Whether or not to overwrite existing renderers.

class NavigationItem[source]

Bases: object

Base for all items in a Navigation.

Every item inside a navigational view should derive from this class.

active = False

Indicates whether or not the item represents the currently active route

render(renderer=None, **kwargs)[source]

Render the navigational item using a renderer.

Parameters:

renderer – An object implementing the Renderer interface.

Returns:

A markupsafe string with the rendered result.

Bases: NavigationItem

An item that contains a link to a destination and a title.

get_url()[source]

Returns the URL to the destination.

class RawTag(content, **attribs)[source]

Bases: NavigationItem

An item usually expressed by a single HTML tag.

Parameters:
  • title – The text inside the tag.

  • attribs – Attributes on the item.

class View(text, endpoint, **kwargs)[source]

Bases: Link

Application-internal link.

The endpoint, *args and **kwargs are passed on to url_for() to get the link.

Parameters:
  • text – The text for the link.

  • endpoint – The name of the view.

  • kwargs – Extra keyword arguments for url_for()

ignore_query = True

By default, query arguments are ignored.”””

get_url()[source]

Return url for this item.

Returns:

A string with a link.

property active

Return True it view is active.

class Separator[source]

Bases: NavigationItem

Separator.

A seperator inside the main navigational menu or a Subgroup. Not all renderers render these (or sometimes only inside Subgroups).

class Subgroup(title, *items)[source]

Bases: NavigationItem

Nested substructure.

Usually used to express a submenu.

Parameters:
  • title – The title to display (i.e. when using dropdown-menus, this text will be on the button).

  • items – Any number of NavigationItem instances that make up the navigation element.

property active

Return True if any element is currently active.

class Text(text)[source]

Bases: NavigationItem

Label text.

Not a <label> text, but a text label nonetheless. Precise representation is up to the renderer, but most likely something like <span>, <div> or similar.

class Navbar(title, *items)[source]

Bases: Subgroup

Top level navbar.

class Renderer[source]

Bases: Visitor

Base interface for navigation renderers.

Visiting a node should return a string or an object that converts to a string containing HTML.

visit_object(node)[source]

Fallback rendering for objects.

If the current application is in debug-mode (flask.current_app.debug is True), an <!-- HTML comment --> will be rendered, indicating which class is missing a visitation function.

Outside of debug-mode, returns an empty string.

class SimpleRenderer(**kwargs)[source]

Bases: Renderer

A very basic HTML5 renderer.

Renders a navigational structure using <nav> and <ul> tags that can be styled using modern CSS.

Parameters:

kwargs – Additional attributes to pass on to the root <nav>-tag.

Returns arefs matching url.

visit_Navbar(node)[source]

Returns navbar classes.

visit_View(node)[source]

Returns arefs.

visit_Subgroup(node)[source]

Returns subgroup divs.

visit_Separator(node)[source]

Returns separator hrs.

visit_Text(node)[source]

Returns nav-label spans.

class BootStrap5Renderer(**kwargs)[source]

Bases: Renderer

A very basic Bootstrap 5 renderer.

Renders a navigational structure using <nav> and <ul> tags that can be styled using modern CSS.

Parameters:

kwargs – Additional attributes to pass on to the root <nav>-tag.

Returns arefs matching url.

visit_Navbar(node)[source]

Returns navbar classes.

visit_View(node)[source]

Returns arefs.

visit_Subgroup(node)[source]

Returns subgroup divs.

visit_Separator(node)[source]

Returns separator hrs.

visit_Text(node)[source]

Returns nav-label spans.