HELP - Django variable in style (width) attribute

瀏覽次數:171 次
跳到第一則未讀訊息

Aline C. R. Souza

未讀,
2016年10月15日 晚上9:28:382016/10/15
收件者:Django users
Hello Guys,

Why the template tag call {% get_percentage question.pk choice.pk %} works inside the span tag, but doesn't work in style (width) attribute?

What is wrong?

 {% for choice in question.choice_set.all %}
        <strong>{{ choice.choice_text }}</strong>
        <span class="pull-right">{% get_percentage question.pk choice.pk %}%</span>
        <div class="progress progress-danger active">
            <div class="bar" style="width:{% get_percentage question.pk choice.pk %}%"></div>
        </div>
 {% endfor %}

I am using Python 3.5.2 and Django 1.10.2


PS: I did the same question on StackOverflow: http://stackoverflow.com/q/40065604/5498125, but I have no answers yet.

James Schneider

未讀,
2016年10月15日 晚上10:53:412016/10/15
收件者:django...@googlegroups.com


> Why the template tag call {% get_percentage question.pk choice.pk %} works inside the span tag, but doesn't work in style (width) attribute?
>
> What is wrong?
>

No idea. You haven't provided what your template tag does, or what the rendered template looks like.

What does the final HTML look like?

-James

Constantine Covtushenko

未讀,
2016年10月16日 凌晨2:49:122016/10/16
收件者:django...@googlegroups.com
Hi Aline,

It is not direct answer for what you are asking,
but why do you calculate the percentage 2 times?

Why just use `with` tag?

With it nor problem at all.

Hope that helps.

Regards,
Constantine C.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciV9%2Bp79D4Gkst8khnhmDVt3nUOrA2C6-uWXgmVi8p-rDw%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Aline C. R. Souza

未讀,
2016年10月20日 下午3:15:302016/10/20
收件者:Django users
Thank you both, Constantine and James. Thanks to your comments I could realize where the error was, and I could improvve performance assigning the returned value to a variable.

The error was in html, and not django. When I looked at the rendered html, I could see the error.
回覆所有人
回覆作者
轉寄
0 則新訊息