template.Engine

class Engine(dirs=None, app_dirs=False, context_processors=None, debug=False, loaders=None, string_if_invalid='', file_charset='utf-8', libraries=None, builtins=None, autoescape=True) [source] When instantiating an Engine all arguments must be passed as keyword arguments: dirs is a list of directories where the engine should look for template source files. It is used to configure filesystem.Loader. It defaults to an empty list. app_dirs only affects the default value of loaders. See below

template.Engine.from_string()

Engine.from_string(template_code) [source] Compiles the given template code and returns a Template object.

template.Engine.get_template()

Engine.get_template(template_name) [source] Loads a template with the given name, compiles it and returns a Template object.

template.Engine.select_template()

Engine.select_template(self, template_name_list) [source] Like get_template(), except it takes a list of names and returns the first template that was found.

template.Library.assignment_tag()

django.template.Library.assignment_tag() Deprecated since version 1.9: simple_tag can now store results in a template variable and should be used instead. To ease the creation of tags setting a variable in the context, Django provides a helper function, assignment_tag. This function works the same way as simple_tag() except that it stores the tag’s result in a specified context variable instead of directly outputting it. Our earlier current_time function could thus be written like this: @r

template.Library.filter()

django.template.Library.filter() Once you’ve written your filter definition, you need to register it with your Library instance, to make it available to Django’s template language: register.filter('cut', cut) register.filter('lower', lower) The Library.filter() method takes two arguments: The name of the filter – a string. The compilation function – a Python function (not the name of the function as a string). You can use register.filter() as a decorator instead: @register.filter(name='cu

template.Library.inclusion_tag()

django.template.Library.inclusion_tag() Another common type of template tag is the type that displays some data by rendering another template. For example, Django’s admin interface uses custom template tags to display the buttons along the bottom of the “add/change” form pages. Those buttons always look the same, but the link targets change depending on the object being edited – so they’re a perfect case for using a small template that is filled with details from the current object. (In the

template.Library.simple_tag()

django.template.Library.simple_tag() Many template tags take a number of arguments – strings or template variables – and return a result after doing some processing based solely on the input arguments and some external information. For example, a current_time tag might accept a format string and return the time as a string formatted accordingly. To ease the creation of these types of tags, Django provides a helper function, simple_tag. This function, which is a method of django.template.Libr

template.loader.get_template()

get_template(template_name, using=None) [source] This function loads the template with the given name and returns a Template object. The exact type of the return value depends on the backend that loaded the template. Each backend has its own Template class. get_template() tries each template engine in order until one succeeds. If the template cannot be found, it raises TemplateDoesNotExist. If the template is found but contains invalid syntax, it raises TemplateSyntaxError. How templates are

template.loader.render_to_string()

render_to_string(template_name, context=None, request=None, using=None) [source] render_to_string() loads a template like get_template() and calls its render() method immediately. It takes the following arguments. template_name The name of the template to load and render. If it’s a list of template names, Django uses select_template() instead of get_template() to find the template. context A dict to be used as the template’s context for rendering. request An optional HttpRequest that w