Django Book 翻译
菜单>:
TOC
返回
原文:
Here, instead of manually specifying the context dictionary as before, we pass the value of ``locals()`` , which will include all variables defined at that point in the functions execution. As a consequence, weve renamed the ``now`` variable to ``current_date`` , because thats the variable name that the template expects. In this example, ``locals()`` doesnt offer a *huge* improvement, but this technique can save you some typing if you have several template variables to defineor if youre lazy.
翻译:
在此,我们没有像之前那样手工指定 context 字典,而是传入了 ``locals()`` 的值,它囊括了函数执行到该时间点时所定义的一切变量。因此,我们将 ``now`` 变量重命名为 ``current_date`` ,因为那才是模板所预期的变量名称。在本例中, ``locals()`` 并没有带来多 *大* 的改进,但是如果有多个模板变量要界定而你又想偷懒,这种技术可以减少一些键盘输入。
备注:
译者: