This is sort of an odd question, not sure if it's a bug or it's something silly I've done.
In my views.py,
def display(request):
altTrue = []
altFalse = []
altTrue, altFalse = altCheck(soup)
results = { 'alttrue' : altTrue,
'altfalse' : altFalse,
}
return render(request, 'results.html', results)
def altCheck(soup):
alttrue = []
altfalse = []
#The multimedia tags we're searching for
multimedialist = ['img','input','area']
#Return all tags from multimedia list and check if alt is present in them
for tag in multimedialist:
for incodetag in soup.findAll(tag):
if incodetag.get('alt') is None:
altfalse.append(incodetag)
else:
alttrue.append(incodetag)
return alttrue, altfalse
In my results.html,
{{ alttrue }} <!-- Prints out the list successfully -->
{% for tag in alttrue %} <!--Prints out [] but with correct count-->
{{ tag }}
{% endfor %}
I am validating whether the list is empty or not before trying to print but still. The moment I run the list through a for loop, I get as many []s as the number of actual elements in the list.
Strangely, when I tried the same thing on my Python interpreter, my result came out fine, regardless of whether I printed out the object directly or If I used a loop.
Am I missing something?
Thanks in advance!
{{ alttrue }}? Presumably it is a list of strings?dispayview has to take request.[<img height="50" src="assets/images/logo.png" width="50"/>, <input class="form-control" placeholder="Search" type="text"/>]is not a list of strings, the quotes are necessary, If am not mistaken it's list of BS objects and this can explain why you can't loop over it so easy.