2017-12-11 15 views
0

私のテンプレートタグ: -もし条件djangoでテンプレートタグを使う方法?

@register.filter("participants_count_in_sessions") 
def participants_count_in_sessions(session_id): 
    class_session_participants_count = ClassJoin.objects.using('p5M').filter(classSession=session_id).count() 
    return class_session_participants_count 

とあれば内部でどのように私は私のテンプレートでそれを使用しています: - 私はこの方法を使用して取得しています

{% for item in data_list %} 
<td class="text-center">{% if item.id | participants_count_in_sessions %}<a href="#">{% endif %}{{ item.id | participants_count_in_sessions }}</a></td> 
{% endfor%} 

とエラー: -

TemplateSyntaxError at /session-on-the-basis-of-class/1/ Could not parse the remainder: '|' from '|'

答えて

1

フィルタパイプ間のスペースを削除する必要があります。

{% if item.id|participants_count_in_sessions %} 

template languageは空白がない場合にのみフィルタとして認識します。そうでなければ、テンプレートタグに変数を渡していると見なして解析できません。

+0

ありがとう –

関連する問題