'django - get 'REMOTE_USER' from middleware class

We use kerberos for our authentication. Using

request.META['REMOTE_USER']

I am able to get the authenticated user in my views.py however when I move this to a custom middleware class inside the

def process_request(self, request):

I keep getting the following error

user = request.META['REMOTE_USER']
KeyError: 'REMOTE_USER'

How do I read the authenticated user from my middleware?



Solution 1:[1]

I think the problem is your middleware is executing first than the middleware that fill out that info. Try to change the order of your middleware in the settings.py file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 levi