Django:什么是“加载”做(在模板文件)? [英] Django: what does "load" do (in a template file)?

查看:121
本文介绍了Django:什么是“加载”做(在模板文件)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于加载对于搜索来说太普遍:


  1. 加载的目的是什么?在这种特殊情况下呢? - 在模板文件中,base_weblog.html



    {%load weblog%} {%render_month_links%}


  2. 为了加载到
    ,是否使用了一些命名约定?例如。文件夹和/或文件的名称和/或
    类名称?


  3. 加载的文档在哪里,您可以详细说明? p>







详细信息:



示例来自
的来源 http://www.djangoproject.com/ - 直接下载网址是
,通过 http://shrinkster.com/17g8



部分文件夹结构(没有文件扩展名的项目是文件夹):

  django_website 

应用程序
帐户
聚合器
博客
urls.py
models.py
类条目(models.Model)

templatetags
weblog.py
联系
docs

模板
base_weblog.html

聚合器
blog
entry_archive.html
entry_archive_year.html
mon th_links_snippet.html
entry_archive_month.html
entry_detail.html
entry_snippet.html
entry_archive_day.html
评论
联系
docs
feed
flatfiles
flatpages
注册


解决方案<在加载(在模板文件 django_website / templates / base_weblog.html )中的div>

weblog指文件 weblog.py 在文件夹 django_website / apps / blog / templatetags 中。文件夹 templatetags 必须完全命名,并且必须包含名为 __ init __。py (问题2)的文件。



加载使自定义模板标签( render_latest_blog_entries render_month_links 在这种情况下)可用于模板, django_website\templates\base_weblog.html 在这种情况下。 加载是一种安全和性能功能。


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

解决方案

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

这篇关于Django:什么是“加载”做(在模板文件)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆