Utils#

Overview#

Django Simple Page provides some utilities to make your life easier. These are some template tags - mainly the menu tag to render a navigation menu for your pages. And a page view function you could use in your url configuration. You are free to use them or not.

Api Reference#

Template tags and filters#

simple_page.templatetags.simple_page.menu(page, max_level=None, include_root=False)#

An inclusion tag to generate a tree based menu using nested lists. The current page and its ancestors will be marked as active by a css class “active”. Each menu list will have a css class “nav-level-x” where x is the level of the menu starting with 1.

The template being used for rendering the menu is “simple_page/menu.html”. You can overwrite it to your needs. The context for the template will contain the following variables:

  • page: the current page

  • max_level: the maximum level of submenus

  • nodes: the page nodes to be rendered in the menu

  • root: the root page if include_root is True, otherwise None

Parameters:
  • page (Page) – current page

  • max_level (int) – maximum level of submenus, defaults to None

  • include_root (bool) – whether to include the root page, defaults to False

Return dict:

the context for the menu template

simple_page.templatetags.simple_page.is_active(page, node)#

Filter tag returning True for the current page and its ancestors. False otherwise.

Parameters:
  • page (Page) – current page

  • node (Page) – the page node to check

Return bool:

True if the node is active, False otherwise

simple_page.templatetags.simple_page.level(node)#

Filter tag returning the level of the page node starting with 1.

Parameters:

node (Page) – the page node

Return int:

the level of the page node

Page view#

simple_page.views.page_view(request, slug, **kwargs)#

Simple view function for pages. Get the page by its slug, find the right renderer for it and return a HTTP response with the rendered page.

Parameters:
  • request (HttpRequest) – HTTP request

  • slug (str) – slug of the page to be rendered

  • kwargs – Additional data as keyword arguments (default empty dict)

Returns:

HTTP response with the rendered page

Return type:

HttpResponse

Raises:

Http404 – if no page with the given slug exists