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

人盡茶涼 提交于 2019-12-08 14:31:57

问题


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

回答1:


load:

Load a custom template tag set.

See Custom tag and filter libraries for more information.




回答2:


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



来源:https://stackoverflow.com/questions/1048232/django-what-does-load-do-in-a-template-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!