2011-12-15 21 views
38

Django şablonlama sisteminde bir değişkeni nasıl atayabilirim?Django: Şablonda değişken atamak

{% restaurant_id as restaurant.id %} veya {{ restaurant_id as restaurant.id }} çalışmıyor: Restaurant varsayarsak

bir modelidir.

cevap

71

Sen with template tag kullanın ve böyle bir iç şablon değişkenini atamak olabilir:

{% with restaurant_id=restaurant.id %} 
... use restaurant_id in this template section ... 
{% endwith %} 
14

Not: filtrelerden yararlanabilirsiniz şablon etiketi "ile":

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