I have a very simple dictionary with some data on it:
some_data= {'totalsForAllResults': {'ga:sessions': '11'}, 'profileInfo': {'internalWebPropertyId': '104132673', 'accountId': '67836206', 'profileName': 'My New Cool Site', 'webPropertyId': 'UA-677293506-1', 'profileId': '108628346', 'tableId': 'ga:108372846'},
on my views I have:
sessions = some_data['totalsForAllResults']['ga:sessions']
account_id = some_data['profileInfo']['accountId']
property_id = some_data['profileInfo']['internalWebPropertyId']
property_name = some_data['profileInfo']['profileName']
print(sessions,account_id,property_id,property_name)
return render(request, 'ga_app/report.html', {'sessions':sessions},
{'account_id':account_id},
{'property_id':property_id},
{'property_name':property_name},)
The variables get printed perfectly on my shell, however django doesn't want to pass them to the templates, I keep getting TypeError: unhashable type: 'dict' but I'm sending variables to the template not a dictionary. Why this happens?
Change this:
return render(request, 'ga_app/report.html', {'sessions':sessions},
{'account_id':account_id},
{'property_id':property_id},
{'property_name':property_name},)
to this:
return render(request, 'ga_app/report.html', {'sessions': sessions,
'account_id': account_id,
'property_id':property_id,
'property_name':property_name}
)
You have to pass one dict as the context. You are passing 4 of them!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With