I’m trying to do the following in my Django template:
{% for embed in embeds %} {% embed2 = embed.replace('<', '<') %} {{embed2}}<br /> {% endfor %}
However, I always get an invalid block or some syntax error when I do anything like that (by that I mean {% %} code inside a loop). Python doesn’t have {} to signify ‘scope’ so I think this might be my problem? Am I formatting my code wrong?
Edit: the exact error is: Invalid block tag: 'embed2'
Edit2: Since someone said what I’m doing is not supported by Django templates, I rewrote the code, putting the logic in the view. I now have:
embed_list = [] for embed in embeds: embed_list[len(embed_list):] = [embed.replace('<', '<')] #this is line 35 return render_to_response('scanvideos.html', { 'embed_list' :embed_list })
However, I now get an error: 'NoneType' object is not callable' on line 35.
Instead of using a slice assignment to grow a list
embed_list[len(embed_list):] = [foo]you should probably just do
embed_list.append(foo)But really you should try unescaping html with a library function rather than doing it yourself.
That NoneType error sounds like embed.replace is None at some point, which only makes sense if your list is not a list of strings – you might want to double-check that with some asserts or something similar.