HTML forloop – double

I am in my HTML file for my website. The first forloop checks to see what account the user is logged into and then only displays that user's data and it works perfectly on its own.

{% for item in user.Doc.all %}

The second forloop loops through all the data that "__stratswith"Title: " and displays it and this works perfectly on its own.

{% for post in templates %}

I am using Django and python to build the website and once running into this problem I have researched if there is any other way to loop through the forloops in a different location like my file and I have had no luck. I need to do it in the HTML but when I write this...

{% for item in user.Doc.all %}
    {% for post in item.templates %}
        {{ post.content }}
    {% endfor %}
{% endfor %}

It doesn't work. It indicated that there is data trying to be displayed because I have an if statement before the for-loops but no data is displayed. I need the proper way to write a nested forloop in an HTML file properly and I cant figure it out. The example I have should work in my mind and the research that I have done but it doesn't. I found this and this which mentions forloop.parentloop and that's the closest I've gotten in days and still no luck. Thanks for any help!

This is my just in case but it doesn't show much:

def docpostlistview(request):
    docs = DocPost.objects.all()
    context = {"docs": docs}

    context['templates'] = DocPost.objects.filter(title__startswith="Temp: ")
    return render(request, 'my_app/docpost_list.html', context)

Read more here:

Content Attribution

This content was originally published by Russell Hertel at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: