Maktabun
Maktabun

Reputation: 114

django template looping through a list

I am trying to loop through a simple list like

{% for x in y %}
<p>My name is {{ x }}</p>
{% endfor %}

My vies is like this

def listloop(request):
    y= ['John', 'Julie', 'Pat']
    context ={'x':y}
    return render(requst, 'index.html', context)

But this showing blank page. Please help What I'm doing wrong. Thanks.

Upvotes: 0

Views: 1173

Answers (1)

catavaran
catavaran

Reputation: 45585

You misnamed context variable in dict. It shoould be:

def listloop(request):
    y = ['John', 'Julie', 'Pat']
    context = {'y': y} # 'y' instead of 'x'
    return render(requst, 'index.html', context)

Upvotes: 2

Related Questions