I'm confused with HttpRequest object in Django. I know that the AuthenticationMiddleware will add a user
to request
which is an instance of HttpRequest. And the code is here, but what I want to show is as follow:
request.user = SimpleLazyObject(lambda: get_user(request))
I have read the code of HttpRequest object and can not find a user
attribute and its code don't have a __setattr__
method. So I'm curious about why the code do not raise an AtrributeError when access to a no existing attribute.
Thanks for giving help.
Copyright Notice:Content Author:「chyoo CHENG」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/37586062/httprequest-instance-add-attribute-dynamically-in-django