for key,value not working in template

Hi,

I have a function in my view that should render a page with some data from a dictionary.

my function use render for this purpose as following:

def welcome_page(request):

    return render(request, "jobportal/index.html",regions)

where regions is:

regions = {

“France”: 30534,

“Spain”: 13614,

“Italy": 93474

}

regions is defined in the same view as my function welcome page.

in my template I have thefollowing code:

<ul>

  {% for key, value in regions.items %}

  <li>{{ key }} : {{ value }}</li>

  {% endfor %}

</ul>

while the template works (display my other section of the page, I’m not able to get regions displayed correctly.

I read the documentation as also several examples and it seems that everything is good. So why don’t I get regions displayed ?

thx

render takes a context within which you should have your regions

render(request, "jobportal/index.html",{"regions": regions})

Then I think it should work.

1 Like

Yes, you’re right. I was confused with “double” word “regions”. thx for saving me :slight_smile:

1 Like