Cannot assign window.user to req.user object in javascript with Swig

I am using Swig as the template engine.

I want to assign req.user to the window.user. Therefore I am doing:

window.user = {{user|json|safe}};

in javascript. But I cannot use {{user}} in other views. Where am I wrong?