8.11.2012 2:45, Beau Hargis kirjoitti:
> Creating a custom API to login users which worked under 0.4.0, but does
> not work on with 2.1.x.
>
> The problem is that the request object that the view gets does not allow
> attributes to be set as the standard django HttpRequest object does. So,
> when the user credentials are validated and some custom checks
> performed, the request object is passed to the login function and I get
> an 'AttributeError: can't set attribute' when attempting to set the user
> attribute on the request object:
>
> 72.
>
> request.session[SESSION_KEY] =
user.id
>
> 73.
>
> request.session[BACKEND_SESSION_KEY] = user.backend
>
> 74.
>
> if hasattr(request, 'user'):
>
> 75.
>
> * request.user = user*
>
> I can work around this by creating a property to return the original
> HttpRequest object and pass that along to the functions, but I wanted to
> ping the group and see if anyone else had any thoughts.
>
This is known issue with DRF2.
Though your login procedure is incorrect (see Django docs how you should
do the login) it would result the same error.
Problem is that DRF2 doesn't use Django HttpRequest but a wrapper around
it where user is read only. I was supposed to make a patch for it but so
far I hadn't have any time for it :)
You can get around of it when you need to pass request object to a
authentication function you can use undocumented feature and pass
"request._request" which points to original django HttpRequest.
--
Jani Tiainen
- Well planned is half done and a half done has been sufficient before...