選單
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

with Template Tag


示例

Create a variable in the template, and use it

{% with firstname="Stalikken" %}
  <h1>Hello {{ firstname }}</h1>
{% endwith %}
執行示例 »

定義和用法

The with tag is used to create variables in Django templates.

This can be useful when you need to ask for the same variable many times, like in a loop

示例

Use the with tag to get the length of fruits only one time

{% with myvar=fruits|length %}
  {% for x in fruits %}
    <p>{{ x }} is one of {{ myvar }} fruits.</p>
  {% endfor %}
{% endwith %}
執行示例 »

語法

{% with var1=val1 var2=val2 var3=val3 etc. %}
...
{% endwith %}

引數

描述
var1=val1 var2=val2 var3=val3 etc. Required. Declaring variable(s) and their value(s).

×

聯絡銷售

如果您想將 W3Schools 服務用於教育機構、團隊或企業,請傳送電子郵件給我們
sales@w3schools.com

報告錯誤

如果您想報告錯誤,或想提出建議,請傳送電子郵件給我們
help@w3schools.com

W3Schools 經過最佳化,旨在方便學習和培訓。示例可能經過簡化,以提高閱讀和學習體驗。教程、參考資料和示例會不斷審查,以避免錯誤,但我們無法保證所有內容的完全正確性。使用 W3Schools 即表示您已閱讀並接受我們的使用條款Cookie 和隱私政策

版權所有 1999-2024 Refsnes Data。保留所有權利。W3Schools 由 W3.CSS 提供支援