As "load" is far too generic for searching:
What is the purpose of "load" and what does it do in this particular case? - in a template file, base_weblog.html,
{% load weblog %}{% render_month_links %}
Are some naming conventions used in order for "load" to do its job? E.g. names of folders and/or files and/or class names?
Where is the documentation for "load" and can you elaborate?
Details:
The example is from the source for http://www.djangoproject.com/ - direct download URL is through http://shrinkster.com/17g8.
Partial folder structure (items with no file extension are folders):
django_website apps accounts aggregator blog urls.py models.py class Entry(models.Model) templatetags weblog.py contact docs templates base_weblog.html aggregator blog entry_archive.html entry_archive_year.html month_links_snippet.html entry_archive_month.html entry_detail.html entry_snippet.html entry_archive_day.html comments contact docs feeds flatfiles flatpages registration
For a hands-on example of creating HTML pages with templates, see Tutorial 3. Django defines a standard API for loading and rendering templates regardless of the backend. Loading consists of finding the template for a given identifier and preprocessing it, usually compiling it to an in-memory representation.
{% load static %} tells django to load a set of template tags/filters defined in the file static.py (in a folder templatetags in any of the apps of your project). The same way you can define your own tags, put them in a file util_tags.py and load them with {% load util_tags %} .
include tag loads a template and renders it with the current context. This is a way of “including” other templates within a template. The template name can either be a variable or a hard-coded (quoted) string, in either single or double quotes.
Being a web framework, Django needs a convenient way to generate HTML dynamically. The most common approach relies on templates. A template contains the static parts of the desired HTML output as well as some special syntax describing how dynamic content will be inserted.
load
:
Load a custom template tag set.
See Custom tag and filter libraries for more information.
"weblog" after "load" (in template file django_website/templates/base_weblog.html
) refers to file weblog.py
in folder django_website/apps/blog/templatetags
. Folder templatetags
must be named exactly that and must contain a file named __init__.py
(question 2).
"load" makes the custom template tags (render_latest_blog_entries
and render_month_links
in this case) available for use in templates, django_website\templates\base_weblog.html
in this case. "Load" is a security and performance function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With