1.2.14. template_extras

This module provides functionality for Jinja functions used to generate server page content.

1.2.14.1. Data

functions[source]

A dictionary of the exported page functions.

1.2.14.2. Functions

embed_youtube_video(video_id, autoplay=True, enable_js=False, start=0, end=None)[source]

A Jinja function to embed a video into a web page using YouTube’s iframe API. In order to enable a training button after the video has ended the youtube.js file needs to be included and enable_js just be set to True. If start or end are specified as strings, the must be in a format suitable to be parsed by parse_timespan().

Parameters:
  • video_id (str) – The id of the YouTube video to embed.
  • autoplay (bool) – Start playing the video as soon as the page loads.
  • enable_js (bool) – Enable the Javascript API.
  • start (int, str) – The time offset at which the video should begin playing.
  • end (int, str) – The time offset at which the video should stop playing.
export_function(function)[source]

A decorator to “export” a function by placing it in functions.

Parameters:function (function) – The function to export.
make_csrf_page(url, params, method='POST')[source]

A Jinja function which will create an HTML page that will automatically perform a CSRF attack against another page.

Parameters:
  • url (str) – The URL to use as the form action.
  • params (dict) – The parameters to send in the forged request.
  • method (str) – The HTTP method to use when submitting the form.
make_redirect_page(url, title='Automatic Redirect')[source]

A Jinja function which will create an HTML page that will automatically redirect the viewer to a different url.

Parameters:
  • url (str) – The URL to redirect the user to.
  • title (str) – The title to use in the resulting HTML page.