Im working with django and i would like to store a object (in session?) so i can use this in multiple templates. So similar to the "user" that is always accessible, id like to add one of my own. So i dont have to add it every time in render(request,
What i try so far:
def login_character(request, character_name):
request.session['character'] = Character.objects.get(name=character_name)
return HttpResponseRedirect(reverse('index'))
Template:
{% if 'character' in request.session %}
<p>Jeej there is some character</p>
{{ request.session.character.name }}
{% else %}
<p>Nope, nothing here</p>
{% endif %}
But that doesn't seem to work, Can someone help me out or point in the right direction?
With kind regards, Hans