template.loaders.base.Loader.get_template()

get_template(template_name, skip=None) [source] Returns a Template object for a given template_name by looping through results from get_template_sources() and calling get_contents(). This returns the first matching template. If no template is found, TemplateDoesNotExist is raised. The optional skip argument is a list of origins to ignore when extending templates. This allow templates to extend other templates of the same name. It also used to avoid recursion errors. In general, it is enough

template.loaders.base.Loader

class Loader [source] Loads templates from a given source, such as the filesystem or a database. get_template_sources(template_name) [source] A method that takes a template_name and yields Origin instances for each possible source. For example, the filesystem loader may receive 'index.html' as a template_name argument. This method would yield origins for the full path of index.html as it appears in each template directory the loader looks at. The method doesn’t need to verify that the tem

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

template.loader.select_template()

select_template(template_name_list, using=None) [source] select_template() is just like get_template(), except it takes a list of template names. It tries each name in order and returns the first template that exists. If loading a template fails, the following two exceptions, defined in django.template, may be raised:

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.loaders.app_directories.Loader

class app_directories.Loader Loads templates from Django apps on the filesystem. For each app in INSTALLED_APPS, the loader looks for a templates subdirectory. If the directory exists, Django looks for templates in there. This means you can store templates with your individual apps. This also makes it easy to distribute Django apps with default templates. For example, for this setting: INSTALLED_APPS = ['myproject.polls', 'myproject.music'] ...then get_template('foo.html') will look for foo

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.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.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.Engine.get_template()

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