Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: what does "load" do (in a template file)?

Tags:

As "load" is far too generic for searching:

  1. 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 %}

  2. 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?

  3. 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 
like image 212
Peter Mortensen Avatar asked Jun 26 '09 09:06

Peter Mortensen


People also ask

What is load in Django template?

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.

What is the use of load static?

{% 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 %} .

Which keyword is used to load another template in template file in Django?

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.

What do templates do in Django?

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.


2 Answers

load:

Load a custom template tag set.

See Custom tag and filter libraries for more information.

like image 147
Paolo Bergantino Avatar answered Sep 29 '22 00:09

Paolo Bergantino


"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.

like image 29
Peter Mortensen Avatar answered Sep 28 '22 23:09

Peter Mortensen