template.html
views.py
<!DOCTYPE html>
<html>
<body>
<ul>
{% for x in fruits %}
<li style='color:{% cycle 'red' 'green' 'blue' 'pink' %}'>
{{ x }}
</li>
{% if x == "Banana" %}
{% resetcycle %}
{% endif %}
{% endfor %}
</ul>
<p>Check out views.py to see what the fruits variable looks like.</p>
</body>
</html>
from django.http import HttpResponse
from django.template import loader
def testing(request):
template = loader.get_template('template.html')
context = {
'fruits': ['Apple', 'Banana', 'Cherry', 'Orange']
}
return HttpResponse(template.render(context, request))