Django: Assigning variables in template

前端 未结 2 458
一生所求
一生所求 2021-02-02 05:37

How can I assign a variable inside the django templating system ?

Assuming Restaurant is a Model:

{% restaurant_id as restaurant.id %}

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-02 06:22

    Note: You can use filters within the "with" template tag:

    foo is {{ foo }}
    {% with bar=foo|slice'6:9' %}
      bar is {{ bar }}
    {% endwith %}
    

提交回复
热议问题