Render multiple objects from Django model using request function

Solution 1:

Can you share template? Anyway, i guess the problem is here:

return render(request, 'core/frontpage.html', {'jobs': jobs, 'jobs':all_jobs})

You are trying to add two same keywords to dict: 'jobs' and 'jobs'. There should be something like:

return render(request, 'core/frontpage.html', {'jobs': jobs, 'all_jobs':all_jobs})

And then use jobs and all_jobs objects in your template

Solution 2:

As said. return render(request, 'core/frontpage.html', {'jobs': jobs, 'all_jobs':all_jobs}) and in 'core/frontpage.html' .. second time 'jobs' comes , where you wanna list all jobs..replace it with 'all_jobs'..

Further Explaination,

  • Third argument to render() is a dictionary.Its called context. ( i guess)
  • Its key value pairs. The ones in quotes are the keys.After the ':' is its value. value can be any data type or obj.
  • These keys are send to the template , ie the html page you are rendering , here 'core/frontpage.html'.
  • Those keys can be used as variable in the template(html page) for examle .. loop through it,if it is a iterable(like list or like here, a queryset)
  • In your code, you assigned the key 'jobs' twice.. {'jobs': jobs, 'jobs':all_jobs}.. the second overrites the first.