Answer the question
In order to leave comments, you need to log in
Why are there so many spaces in django templates?
There is such a view:
class IndexView(View):
def get(self, request):
data = {}
data['mx1'] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
return render(request, 'index.html', data)
<body>
{% for mx in mx1 %}
{{ mx }}
{% endfor %}
</body>
Answer the question
In order to leave comments, you need to log in
Because in your code, both the instruction {% for mx in mx1 %}
and {% endfor %}
end with a line break character, which does not disappear after the template is processed. Either write a one-line loop, or use the spaceless tag to remove whitespace characters .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question