2017-09-21 5 views
0

Businessというアプリ内でコンテキストのプロセッサとしてビジネスの詳細を追加しようとしています。私はそれに__init__.pybusiness_tags.pyファイルのtemplatetagsという名前のフォルダを含めました。私の問題は、コンテキストプロセッサが結果を表示している間、私は結果をループとして表示できません。Djangoコンテキストプロセッサ用のオブジェクトを表示

business_tags.pyファイル:私のビューファイルで

from django import template 
register = template.Library() 
from django.contrib.auth.models import User 
from ..models import Businessprofile 

@register.simple_tag 
def my_biz(request): 
    current_user = request.user.id 
    biz = Businessprofile.objects.filter(owner=current_user) 

    return biz 

私は現在のために/ ENDFORループのために作られています:

私のようにコンテキストプロセッサの結果を表示するにはどうすればよい
<!--content--> 
{% load business_tags %} 

{% my_biz request %} 

{% for biz in my_biz %} 
    {{ biz }} 
{% endfor %} 
<!--end content--> 

forループ?

{% my_biz request as my_biz_var %} 

{% for biz in my_biz_var %} 
    {{ biz }} 
{% empty %} 
    my_biz_var is empty 
{% endfor %} 

Aditionalノート:あるとして

+0

なぜあなたは、これは明らかにテンプレートタグであるとき、コンテキストプロセッサについて話し続けるのですか? –

答えて

0

あなたの簡単なタグは、ちょうどオブジェクトを(それが「my_biz」に保存されません)、あなたはこのように変数に戻り値を保存する必要が戻っていますDaniDaniel Rosemanが指摘しているように、あなたがやっているのはコンテキストプロセッサではなく単純なタグです。

コンテキストprocesors: https://docs.djangoproject.com/en/1.11/ref/templates/api/#django.template.RequestContext

シンプルタグ:

https://docs.djangoproject.com/en/1.11/howto/custom-template-tags/#simple-tags

+0

それはあなたのために働いたのですか? – Nazkter

関連する問題