<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                下面的幾節涵蓋了可能被應用啟用的 Jinja2 內置的擴展。應用也可以提供進一步 的擴展,但這不會在此描述。會有獨立的文檔來解釋那種情況下的擴展。 ### i18n[](http://docs.jinkan.org/docs/jinja2/templates.html#i18n "Permalink to this headline") 如果啟用來 i18n 擴展,可以把模板中的部分標記為可譯的。標記一個段為可譯的,可 以使用?trans: ~~~ <p>{% trans %}Hello {{ user }}!{% endtrans %}</p> ~~~ 要翻譯一個模板表達式——比如使用模板過濾器或訪問對象的屬性——你需要綁定表達式到 一個名稱來在翻譯塊中使用: ~~~ <p>{% trans user=user.username %}Hello {{ user }}!{% endtrans %}</p> ~~~ 如果你需要在?trans?標簽中綁定一個以上的表達式,用逗號來分割(?,?): ~~~ {% trans book_title=book.title, author=author.name %} This is {{ book_title }} by {{ author }} {% endtrans %} ~~~ 在翻譯塊中不允許使用語句,只能使用變量標簽。 為表示復數,在?trans?和?endtrans?之間用?pluralize?標簽同時指定單數和復 數形式: ~~~ {% trans count=list|length %} There is {{ count }} {{ name }} object. {% pluralize %} There are {{ count }} {{ name }} objects. {% endtrans %} ~~~ 默認情況下塊中的第一個變量用于決定使用單數還是復數。如果這不奏效,你可以指定 用于復數的名稱作為?pluralize?的參數: ~~~ {% trans ..., user_count=users|length %}... {% pluralize user_count %}...{% endtrans %} ~~~ 也可以翻譯表達式中的字符串。為此,有三個函數: _?gettext: 翻譯一個單數字符串 -?ngettext: 翻譯一個復數字符串 -?_:?gettext?的別名 例如你可以容易地這樣打印一個已翻譯的字符串: ~~~ {{ _('Hello World!') }} ~~~ 你可以使用?format?過濾器來使用占位符: ~~~ {{ _('Hello %(user)s!')|format(user=user.username) }} ~~~ 因為其它語言可能不會用同樣的順序使用詞匯,要使用多個占位符,應始終用字符 串參數傳給?format?。 Changed in version 2.5. 如果激活了新樣式的 gettext 調用(?[*新樣式 Gettext*](http://docs.jinkan.org/docs/jinja2/extensions.html#newstyle-gettext)?),使用占位符 會更加簡單: ~~~ {{ gettext('Hello World!') }} {{ gettext('Hello %(name)s!', name='World') }} {{ ngettext('%(num)d apple', '%(num)d apples', apples|count) }} ~~~ 注意?ngettext?函數的格式化字符串自動接受?num?參數作為計數作為附加的 常規參數。 ### 表達式語句[](http://docs.jinkan.org/docs/jinja2/templates.html#id39 "Permalink to this headline") 如果加載了表達式語句擴展,一個名為?do?的擴展即可用。它工作幾乎如同常規的變量 表達式(?{{?...?}}?),只是它不打印任何東西。這可以用于修改列表: ~~~ {% do navigation.append('a string') %} ~~~ ### 循環控制[](http://docs.jinkan.org/docs/jinja2/templates.html#id40 "Permalink to this headline") 如果應用啟用來?[*循環控制*](http://docs.jinkan.org/docs/jinja2/extensions.html#loopcontrols-extension)?,則可以在循環中使用?break?和?continue?。到達?break?時,循環終止。到達?continue?時,當前處理會終止并 從下一次迭代繼續。 這個循環每兩項跳過一次: ~~~ {% for user in users %} {%- if loop.index is even %}{% continue %}{% endif %} ... {% endfor %} ~~~ 同樣,這個循環 10 次迭代之后會終止處理: ~~~ {% for user in users %} {%- if loop.index >= 10 %}{% break %}{% endif %} {%- endfor %} ~~~ ### With 語句[](http://docs.jinkan.org/docs/jinja2/templates.html#with "Permalink to this headline") New in version 2.3. 如果應用啟用了?[*With 語句*](http://docs.jinkan.org/docs/jinja2/extensions.html#with-extension)?,將允許在模板中使用?with?關鍵 字。這使得創建一個新的內作用域。這個作用域中的變量在外部是不可見的。 With 用法簡介: ~~~ {% with %} {% set foo = 42 %} {{ foo }} foo is 42 here {% endwith %} foo is not visible here any longer ~~~ 因為在作用域的開始設置變量很常見,你可以在 with 語句里這么做。下面的兩 個例子是等價的: ~~~ {% with foo = 42 %} {{ foo }} {% endwith %} {% with %} {% set foo = 42 %} {{ foo }} {% endwith %} ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看