Reputation: 377
I have dictionary that i pass as context in my django view, it contains contents of one of the database objects.
I want to add new value to dictionary, to pass additional variable to template.
This code unfortunetly wont work. "new" is not added to "k" and passed to template:
def view(request):
lista_baza = Usluga.objects.all()
k= {
'lista_uslug': lista_baza
}
k.update({'new': 'newcontent'})
return render(request, 'main.html', k)
Upvotes: 0
Views: 406
Reputation: 2719
def view(request):
lista_baza = Usluga.objects.all()
k= {
'lista_uslug': lista_baza
}
k['new'] = 'your context'
return render(request, 'main.html', k)
Upvotes: 0
Reputation: 3240
You could add a new key/value pair to your dictionary like this:
k['new']='newcontent'
Hope this helps.
Upvotes: 1