Worn out on such trifles, but I can not figure out how to output the following array)
There is such:
return render(request, 'main.html', {'arrImages': arrImages,'title': arrTitle}) The arrImages array is output without problems. But how to display the title ? I do not understand where you need a loop-it.
<div class="container"> {% for images in arrImages %} <hr> <p class="text-justify"> {{ /////????title }}</p> <img class = "col-12 ml-auto col-12 mr-auto" src={{ images }}> {% endfor %} Where would I not set, does not work, or is it done in one cycle? Sorry for such questions, but I did not find in the internet)
views.py code
def main(request): d3 = requests.get('https://d3.ru/api/posts/?sorting=rating&threshold_date=day').json() arrImages = [] arrTitle = [] arrText = [] try: for data in d3['posts']: imagesPath= ('data', 'link','url') images = reduce(lambda c, k: c[k] if c is not None and k in c else None, imagesPath, data) if images is not None and ".gif" in images and ".gifv" not in images: arrImages.append(images) imagesPath2= ('data', 'media','url') images2 = reduce(lambda c, k: c[k] if c is not None and k in c else None, imagesPath2, data) if images2 is not None: arrImages.append(images2) titlePath= ('data', 'title') textPath= ('data', 'text') title = reduce(lambda c, k: c[k] if c is not None and k in c else None, titlePath, data) text = reduce(lambda c, k: c[k] if c is not None and k in c else None, textPath, data) if title is not None: arrTitle.append(title) if text is not None: arrText.append(text) print('arrImages',arrImages) print('title',arrTitle) print('text',arrText) except BaseException as e: print('ecxeptions: ',e) return render(request, 'main.html', {'arrImages': arrImages,'title': arrTitle})
for images in arrImages, but{% for i in range(len(arrImages)) %}, and then in the right places{{ arrImages[i] }}and{{ title[i] }}- Avernial'title': arrTitlein the code'title': arrTitle- andreymal