簡體   English   中英

關於龍卷風模板文件中的“模塊”

[英]about the “modules” in a template file in tornado

在龍卷風演示中,模板/home.html中的一個名為blog的應用程序的代碼如下:

{% extends "base.html" %}

{% block body %}
{% for entry in entries %}
    {{ modules.Entry(entry) }}
{% end %}
<div><a href="/archive">{{ _("Archive") }}</a></div>
{% end %}

我想知道“模塊”的來源。 我認為應該這樣:

{% module Entry(entry) %}

所以我更改了代碼,它可以正常工作。

有人知道模板文件中“模塊”的來源嗎? 謝謝。

您可以在RequestHandler .__ init__上找到注釋:

# UIModules are available as both `modules` and `_modules` in the
# template namespace.  Historically only `modules` was available
# but could be clobbered by user additions to the namespace.
# The template {% module %} directive looks in `_modules` to avoid
# possible conflicts.

我認為這可能是用舊版本的龍卷風編寫的代碼:)因此,我們應該改用{%module%}。

在RequestHandler .__ init__中:

self.ui["_modules"] = ObjectDict((n, self._ui_module(n, m)) for n, m in
                             application.ui_modules.iteritems())
self.ui["modules"] = self.ui["_modules"]

在RequestHandler.render_string中:

args.update(self.ui)
args.update(kwargs)
return t.generate(**args)

RequestHandler是Handler的子類,並且render_string中包含模塊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM