Django session is not being updated

Good afternoon.
I’m using django sessions with the database, as specified in the documentation tutorial.
My problem is that I need to update the session outside the scope of the view function.
I have something like:

def jonhdoe(request):
    return render(request, 'indexHttpServer.html',context)

And some where inside the doingSomeMath function i´m updating the session like request.session['someStuff'] += 1. any workaround?
best regards

It looks like you’re passing the request to your function. Why do you think there would be a problem accessing the session attribute of that request while in your function?

access the session inside the doingSomeMath() function?
on equestion, the session are strore in the db when some value change or only in the end of the return?

If you’re passing the request into the function as the code at the top shows, sure!

The parameter, request, is a python object. The identifier session is an attribute on that object. You have access to session anywhere you have access to request.

You can find the answer to your question by looking at django.contrib.sessions.middleware.

Keep in mind this is all Python - there’s nothing “special” or “magic” about sessions. They’re just objects available to be used.