Ah, yes, sorry, the default serializer in Django cannot serialise model
instances as it's JSON-based:
https://docs.djangoproject.com/en/1.10/topics/serialization/

You can try switching to an alternate serialiser like pickle which does
(but I don't recommend this), or just put the ID of the user into the
session and then re-fetch it later on.

Andrew

On Thu, Feb 2, 2017 at 12:48 AM, Sgiath <[email protected]> wrote:

> Thanks for explaining.
> I have one problem: when I try to save User object to the channel_session
> I get exception: TypeError: Object of type 'User' is not JSON
> serializable.
> What am I doing wrong? Should I somehow define how to JSON serialize the
> User object?
>
> On Wednesday, February 1, 2017 at 7:01:47 PM UTC+1, Andrew Godwin wrote:
>>
>> Hi,
>> You're right - a lot of the information only appears in the first
>> "connect" message. If you want to persist it, you can use a channel
>> session: http://channels.readthedocs.io/en/stable/getting-
>> started.html#persisting-data
>>
>> This will let you save information (such as the token, or even a User
>> object) into the session in the connect consumer, and then let you use it
>> in other consumers that have the same decorator.
>>
>> Andrew
>>
>>
>> On Wed, Feb 1, 2017 at 5:34 AM, Sgiath <[email protected]> wrote:
>>
>>> Hi,
>>> I am trying to use the query_string parameter and I want to ask what is
>>> the correct way how to use it.
>>> I am using JsonWebsocketConsumer and when debugging I noticed that on
>>> the Handshake the message content contains path, headers, query_string,
>>> client, server, reply_channel and order.
>>> But every other message contains just reply_channel, path, order and
>>> text.
>>> How should I correctly use it? Specifically I want authenticate user
>>> based on the query_string (I send token in it) I can do that in
>>> connection phase but what should I do next? On every other message the user
>>> is AnnonymousUser because there is no query_string. Should I save
>>> query_string into channel_session? Should I save user into
>>> channel_session?
>>> BTW I cannot use user from http session because I am connecting to WS
>>> from the mobile app.
>>>
>>> Thanks
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/django-users/a30535e3-29e1-4547-af70-0e391d1b80d3%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/a30535e3-29e1-4547-af70-0e391d1b80d3%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/4a618140-c90b-4ac8-baab-2aef366545b8%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/4a618140-c90b-4ac8-baab-2aef366545b8%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFwN1uqzq%3DQ2KJEXd2PWWFrOk97nJZD2ouvnUffgnc1mgzq2aA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to