1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #17085, #24783 -- Refactored template library registration.

* Converted the ``libraries`` and ``builtins`` globals of
  ``django.template.base`` into properties of the Engine class.
* Added a public API for explicit registration of libraries and builtins.
This commit is contained in:
Preston Timmons
2015-05-08 15:10:36 -05:00
parent 7b8008a078
commit 655f524915
49 changed files with 949 additions and 594 deletions

View File

@@ -41,7 +41,7 @@ lower level APIs:
Configuring an engine
=====================
.. class:: Engine([dirs][, app_dirs][, allowed_include_roots][, context_processors][, debug][, loaders][, string_if_invalid][, file_charset])
.. class:: Engine([dirs][, app_dirs][, allowed_include_roots][, context_processors][, debug][, loaders][, string_if_invalid][, file_charset][, libraries][, builtins])
.. versionadded:: 1.8
@@ -114,6 +114,34 @@ Configuring an engine
It defaults to ``'utf-8'``.
* ``'libraries'``: A dictionary of labels and dotted Python paths of template
tag modules to register with the template engine. This is used to add new
libraries or provide alternate labels for existing ones. For example::
Engine(
libraries={
'myapp_tags': 'path.to.myapp.tags',
'admin.urls': 'django.contrib.admin.templatetags.admin_urls',
},
)
Libraries can be loaded by passing the corresponding dictionary key to
the :ttag:`{% load %}<load>` tag.
* ``'builtins'``: A list of dotted Python paths of template tag modules to
add to :doc:`built-ins </ref/templates/builtins>`. For example::
Engine(
builtins=['myapp.builtins'],
)
Tags and filters from built-in libraries can be used without first calling
the :ttag:`{% load %}<load>` tag.
.. versionadded:: 1.9
The ``libraries`` and ``builtins`` arguments were added.
.. staticmethod:: Engine.get_default()
When a Django project configures one and only one