44Configuration
55=============
66
7- `django-render-static ` settings are set in the `` STATIC_TEMPLATES `` dictionary in your site
8- settings:
7+ :pypi: `django-render-static ` settings are set in the :setting: ` STATIC_TEMPLATES ` dictionary in your
8+ site settings:
99
1010.. code-block :: python
1111
@@ -37,19 +37,20 @@ settings:
3737 ]
3838 }
3939
40- The `` STATIC_TEMPLATES `` setting closely mirrors the `` TEMPLATES `` setting by defining which
41- template backends should be used. It extends the standard setting with a few options needed by the
42- static engine including a global context available to all static templates and a set of template
43- specific configuration parameters. It's advisable to first read about Django's `` TEMPLATES ` `
44- setting. The main difference with `` STATIC_TEMPLATES ` ` is that it supports batch rendering.
40+ The :setting: ` STATIC_TEMPLATES ` setting closely mirrors the :setting: ` TEMPLATES ` setting by defining
41+ which template backends should be used. It extends the standard setting with a few options needed by
42+ the static engine including a global context available to all static templates and a set of template
43+ specific configuration parameters. It's advisable to first read about Django's :setting: ` TEMPLATES `
44+ setting. The main difference with :setting: ` STATIC_TEMPLATES ` is that it supports batch rendering.
4545Glob-like patterns can be used to select multiple templates for rendering. See :ref: `loaders ` for
4646more details.
4747
4848Minimal Configuration
4949---------------------
5050
51- To run `renderstatic `, If ``STATIC_TEMPLATES `` is not defined in settings. Or, if it's an empty
52- dictionary (or None) then the default engine and loaders will be used which is equivalent to:
51+ To run :django-admin: `renderstatic `, If :setting: `STATIC_TEMPLATES ` is not defined in settings. Or,
52+ if it's an empty dictionary (or None) then the default engine and loaders will be used which is
53+ equivalent to:
5354
5455.. code-block :: python
5556
@@ -69,17 +70,17 @@ dictionary (or None) then the default engine and loaders will be used which is e
6970-----------
7071
7172A prioritized list of backend template engines and their parameters. The engines at the front of the
72- list have precedence over engines further down the list. The ``ENGINES `` parameters are
73- inherited from the standard Django `` TEMPLATES ` ` configuration.
73+ list have precedence over engines further down the list. The ``ENGINES `` parameters are inherited
74+ from the standard Django :setting: ` TEMPLATES ` configuration.
7475
7576``BACKEND ``
7677~~~~~~~~~~~
77- The backend classes that render templates. The standard `` TEMPLATES `` engines should not be used
78- here, instead use the two engines provided by `django-render-static `:
78+ The backend classes that render templates. The standard :setting: ` TEMPLATES ` engines should not be
79+ used here, instead use the two engines provided by :pypi: `django-render-static `:
7980
80- - `` render_static.backends.StaticDjangoTemplates ` `
81- - default app directory: `` static_templates ` `
82- - `` render_static.backends.jinja2.StaticJinja2Templates ` `
81+ - :class: ` render_static.backends.StaticDjangoTemplates `
82+ - default app directory: :setting: ` STATIC_TEMPLATES `
83+ - :class: ` render_static.backends.jinja2.StaticJinja2Templates `
8384 - default app directory: ``static_jinja2 ``
8485
8586If ``APP_DIRS `` is true, or if an app directories loader is used such that templates are searched
@@ -93,55 +94,57 @@ parameter into ``OPTIONS``.
9394A list of configuration parameters to pass to the backend during initialization. Most of these
9495parameters are inherited from the standard Django template backends. One additional parameter
9596``app_dir `` can be used to change the default search path for static templates within apps. The
96- `options available to the StaticDjangoTemplates backend <https://docs.djangoproject.com/en/stable/topics/templates/# django.template.backends.django.DjangoTemplates >`_
97- differ slightly from the `options available to the StaticJinja2Templates backend <https://docs.djangoproject.com/en/stable/topics/templates/# django.template.backends.jinja2.Jinja2 >`_ .
97+ :class: `options available to the StaticDjangoTemplates backend <django.template.backends.django.DjangoTemplates> `
98+ differ slightly from the :class: `options available to the StaticJinja2Templates backend <django.template.backends.jinja2.Jinja2> `.
9899
99100.. _loaders :
100101
101102``loader(s) ``
102103*************
103104
104- Works the same way as the ``loaders `` parameter on ``TEMPLATES ``. Except when using the standard
105- template backend the loaders have been extended and static specific loaders should be used instead:
105+ Works the same way as the ``loaders `` parameter on :setting: `TEMPLATES `. Except when using the
106+ standard template backend the loaders have been extended and static specific loaders should be used
107+ instead:
106108
107- - `` render_static.backends.StaticDjangoTemplates ` `
108- - `` render_static.loaders.django.StaticAppDirectoriesBatchLoader ` ` **default **
109- - `` render_static.loaders.django.StaticFilesystemBatchLoader ` `
110- - `` render_static.loaders.django.StaticAppDirectoriesLoader ` `
111- - `` render_static.loaders.django.StaticFilesystemLoader ` `
112- - `` render_static.loaders.django.StaticLocMemLoader ` `
109+ - :class: ` render_static.backends.StaticDjangoTemplates <render_static.backends.django.StaticDjangoTemplates> `
110+ - :class: ` render_static.loaders.django.StaticAppDirectoriesBatchLoader ` **default **
111+ - :class: ` render_static.loaders.django.StaticFilesystemBatchLoader `
112+ - :class: ` render_static.loaders.django.StaticAppDirectoriesLoader `
113+ - :class: ` render_static.loaders.django.StaticFilesystemLoader `
114+ - :class: ` render_static.loaders.django.StaticLocMemLoader `
113115
114- - `` render_static.backends.jinja2.StaticJinja2Templates ` `
115- - `` render_static.loaders.jinja2.StaticFileSystemBatchLoader ` ` **default **
116- - `` render_static.loaders.jinja2.StaticFileSystemLoader ` `
117- - `` render_static.loaders.jinja2.StaticPackageLoader ` `
118- - `` render_static.loaders.jinja2.StaticPrefixLoader ` `
119- - `` render_static.loaders.jinja2.StaticFunctionLoader ` `
120- - `` render_static.loaders.jinja2.StaticDictLoader ` `
121- - `` render_static.loaders.jinja2.StaticChoiceLoader ` `
122- - `` render_static.loaders.jinja2.StaticModuleLoader ` `
116+ - :class: ` render_static.backends.jinja2.StaticJinja2Templates `
117+ - :class: ` render_static.loaders.jinja2.StaticFileSystemBatchLoader ` **default **
118+ - :class: ` render_static.loaders.jinja2.StaticFileSystemLoader `
119+ - :class: ` render_static.loaders.jinja2.StaticPackageLoader `
120+ - :class: ` render_static.loaders.jinja2.StaticPrefixLoader `
121+ - :class: ` render_static.loaders.jinja2.StaticFunctionLoader `
122+ - :class: ` render_static.loaders.jinja2.StaticDictLoader `
123+ - :class: ` render_static.loaders.jinja2.StaticChoiceLoader `
124+ - :class: ` render_static.loaders.jinja2.StaticModuleLoader `
123125
124126
125127.. note ::
126- The ``StaticJinja2Templates engine `` is configurable with only one loader
127- and the parameter is called ``loader ``. The ``StaticDjangoTemplates ``
128- engine is configurable with more than one loader that are specified as a
129- list under the ``loaders `` parameter.
128+
129+ The :class: `~render_static.backends.jinja2.StaticJinja2Templates ` engine is configurable with
130+ only one loader and the parameter is called ``loader ``. The
131+ :class: `~render_static.backends.django.StaticDjangoTemplates ` engine is configurable with more
132+ than one loader that are specified as a list under the ``loaders `` parameter.
130133
131134
132135The static template engine supports batch rendering. All loaders that have ``Batch `` in the name
133136support wild cards and glob-like patterns when loading templates. By default, if no loaders are
134- specified these loaders are used. For instance, if I wanted to render every .js file in a
135- directory called static_templates/js I could configure templates like so:
137+ specified these loaders are used. For instance, if I wanted to render every .js file in a directory
138+ called static_templates/js I could configure templates like so:
136139
137140.. code-block :: python
138141
139142 ' templates' : [' js/*.js' ]
140143
141144 ``context ``
142145-----------
143- Specify a dictionary containing the context to pass to any static templates as they render. This
144- is the global context that will be applied to all templates. Specific templates can override
146+ Specify a dictionary containing the context to pass to any static templates as they render. This is
147+ the global context that will be applied to all templates. Specific templates can override
145148individual context parameters, but not the whole dictionary. By default all contexts will have the
146149Django settings in them, keyed by ``settings ``.
147150
@@ -177,15 +180,18 @@ For example:
177180 }
178181
179182
180- ``templates ``
181- -------------
183+ ``STATIC_TEMPLATES ``
184+ --------------------
185+
186+ .. setting :: STATIC_TEMPLATES
182187
183- The ``templates `` dictionary lists all templates that should be generated when `renderstatic ` is
184- run with no arguments. If specific configuration directives including rendered path and context are
185- needed for a template they must be specified here. ``templates `` may also be a list containing
186- template names or 2-tuples of template names and configurations. By specifying ``templates `` this
187- way, a single template may be rendered multiple times using different contexts to different
188- locations. For example, the following would render one template three times:
188+ The :setting: `STATIC_TEMPLATES ` dictionary lists all templates that should be generated when
189+ :django-admin: `renderstatic ` is run with no arguments. If specific configuration directives
190+ including rendered path and context are needed for a template they must be specified here.
191+ :setting: `STATIC_TEMPLATES ` may also be a list containing template names or 2-tuples of template
192+ names and configurations. By specifying :setting: `STATIC_TEMPLATES ` this way, a single template may
193+ be rendered multiple times using different contexts to different locations. For example, the
194+ following would render one template three times:
189195
190196.. code-block :: python
191197
@@ -198,9 +204,9 @@ locations. For example, the following would render one template three times:
198204
199205 .. note ::
200206
201- `renderstatic ` will be able to generate templates not listed in `` templates ``, but only if
202- supplied by name on the command line. Contexts may also be augmented/overridden via the command
203- line.
207+ :django-admin: `renderstatic ` will be able to generate templates not listed in
208+ :setting: ` STATIC_TEMPLATES `, but only if supplied by name on the command line. Contexts may
209+ also be augmented/overridden via the command line.
204210
205211``dest ``
206212~~~~~~~~
@@ -226,27 +232,30 @@ any of the same context specifiers that work for the global context.
226232``RENDER_STATIC_REVERSAL_LIMIT ``
227233--------------------------------
228234
229- The guess and check reversal mechanism used to ensure that `urls_to_js ` produces the same reversals
230- as Django's `reverse ` is an **O(n^p) ** operation where **n ** is the number of placeholder candidates
231- to try and **p ** is the number of arguments in the url. Its possible for this to produce a
232- complexity explosion for rare cases where the URL has a large number of arguments with unregistered
233- placeholders. A limit on the number of tries is enforced to guard against this. User's may adjust
234- the limit via the ``RENDER_STATIC_REVERSAL_LIMIT `` settings parameter. By default it is 2**14 tries
235- which runs in ~seconds per URL.
235+ .. setting :: RENDER_STATIC_REVERSAL_LIMIT
236+
237+ The guess and check reversal mechanism used to ensure that :templatetag: `urls_to_js ` produces the
238+ same reversals as Django's :func: `~django.urls.reverse ` is an **O(n^p) ** operation where **n ** is
239+ the number of placeholder candidates to try and **p ** is the number of arguments in the url. Its
240+ possible for this to produce a complexity explosion for rare cases where the URL has a large number
241+ of arguments with unregistered placeholders. A limit on the number of tries is enforced to guard
242+ against this. User's may adjust the limit via the :setting: `RENDER_STATIC_REVERSAL_LIMIT` ` settings
243+ parameter. By default it is 2**14 tries which runs in ~seconds per URL.
236244
237245The solution if this limit is hit, is to provide more specific placeholders as placeholders are
238- attempted in order of specificity where specificity is defined by url name, variable name,
239- app name and/or converter type.
246+ attempted in order of specificity where specificity is defined by url name, variable name, app name
247+ and/or converter type.
240248
241249
242- `` StaticJinja2Templates ` ` Example
243- ---------------------------------
250+ :class: ` ~render_static.backends.jinja2. StaticJinja2Templates ` Example
251+ ---------------------------------------------------------------------
244252
245- Using the ``StaticJinja2Template `` engine requires a slightly different configuration. By
246- default the ``render_static.loaders.jinja2.StaticFileSystemBatchLoader `` loader is used
247- and its ``app_dir `` setting will expect to find templates in static_jinja2 sub directories.
248- For example to render all urls except our admin urls to javascript using (:ref: `urls_to_js `)
249- we might have the following app tree::
253+ Using the :class: `~render_static.backends.jinja2.StaticJinja2Templates ` engine requires a slightly
254+ different configuration. By default the
255+ :class: `render_static.loaders.jinja2.StaticFileSystemBatchLoader ` loader is used and its
256+ ``app_dir `` setting will expect to find templates in static_jinja2 sub directories. For example to
257+ render all urls except our admin urls to javascript using :templatetag: `urls_to_js ` we might have
258+ the following app tree::
250259
251260 .
252261 └── my_app
@@ -255,8 +264,8 @@ we might have the following app tree::
255264 ├── defines.py
256265 ├── models.py
257266 ├── static_jinja2
258- │ └── my_app
259- │ └── urls.js
267+ │ └── my_app
268+ │ └── urls.js
260269 └── urls.py
261270
262271Where our urls.js file might look like:
0 commit comments