-1

I am trying to display the Number of stars for customer review in Django templates.

When i try to assign the value to a variable {{val = customerreview.stars}}

i am getting this error

Could not parse the remainder: ' = customerreview.stars' from 'val = customerreview.stars'

Here is mycode

{% for customerreview in customerreviews %}
<div class=item>
    <div class="rx-client-reviews rx-pading-none">
        <div class="rx-client-img rx-pading-none">
            <img src="img/main01.jpg" alt>
        </div>
        <div class=rx-pading-none>
            <h5>{{customerreview.name}}</h5>
            <h5><a href="index03.html#">{{customerreview.dasignation}}</a></h5>
            <p>{{customerreview.message}}</p>
            <div class=rx-rating>
                <ul>
                    {{val = customerreview.stars}}
                    {% for i in val%}
                    <li><span class="icon icon-Star"></span></li>
                    {% endfor %}

                    <li>
                        <p class=rating-text>{{customerreview.stars}} star rating</p>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>
{% endfor%}

Can someone help me to fix this issue . tnx.

Sathya Baman
  • 3,424
  • 7
  • 44
  • 77

1 Answers1

1

You should use the with tempate tag:

{% with val=customerreview.stars %}
    ...
{% endwith %}

Reference: Django documentation: Built-in template tags and filters

Wtower
  • 18,848
  • 11
  • 103
  • 80
  • TNX. But when i try to loop the value of `val` . i am getting the error `'long' object is not iterable` – Sathya Baman Oct 30 '15 at 10:48
  • 1
    Well, it that might be because `customerreview.stars` is a long number and not eg a list. This has nothing to do with the use of `with`. There is a number of possibilities on how to loop this here: http://stackoverflow.com/questions/1107737/numeric-for-loop-in-django-templates – Wtower Oct 30 '15 at 10:51