BLOG

A LITTLE STORY ABOUT MY JOURNEY

Django get current user globally in the project

Sometimes, you will need to get the current authenticated user in models, or other parts of your app. To achieve this, you must create this middleware in your app(middleware.py) and add it to MIDDLEWARE_CLASSES in project settings: ‘myapp.middleware.GlobalUserMiddlware’

Use Example:

Refrence: http://simionbaws.ro/programming/python-programming/django-python-programming/django-get-current-user-globally-in-the-project/