2016-07-13 5 views

答えて

0

{{ data.4th-of-July.name }} 

そして

{{ data.4th-of-July.slug }} 
+0

私の変数に7月4日が含まれていることを知らなかったらどうしますか?基本的に私はループを通り、x = {u'4th of July ':{' name ':7月4日、' slug ':7月4日}}の値を取得します。 –

+0

@ JohnSmith 'items' - > {keyの%、data.itemsの値%} – Gocht

+0

でテンプレートのdoctを繰り返し処理できます。基本的にはループの後に\tのkey.nameを実行し、私が望む値を得ることができました –

0

は、理想的には、これらのケースでは、あなたがキーを反復処理する必要があります。

はのは、あなたの辞書data呼ぶことにしましょう知事のここに例があります:

{% for key, value in dict_name.items %} <!-- where dict_name denotes name of the dictionary containing {u'4th-of-July': {'name': 4th of July', 'slug': u'4th-of-July'}} --> 
    {{key}} <!-- '4th-of-July' for the index 4th-of-July --> 
    {{value.name}} <!-- equivalent to dict_name.4th-of-July.name for the index 4th-of-July --> 
    {{value.slug}} <!-- equivalent to dict_name.4th-of-July.slug for the index 4th-of-July --> 
{% endfor %} 
関連する問題