Skip to content

CallableBool(True) is not JSON serializable #77

Closed

Description

@wx2228

how do I pass in a boolean? this is the code:

def get_context_data(self, **kwargs):
        ctx = super(QuestionListView, self).get_context_data(**kwargs)
        user = self.request.user
        is_authenticated = user.is_authenticated
        display_name = user.display_name if is_authenticated else None
        reputation_point = user.reputation if is_authenticated else None
        ctx['react_nav'] = render_component(
            'js/nav.jsx',
            props={
                'authenticated': is_authenticated,
                'displayName': display_name,
                'reputation': reputation_point
            })
        return ctx

I can't pass in `is_authenticated` to `props`

Activity

  1. markfinger commented on Jul 6, 2017

    @markfinger
    Owner

    Something like is_authenticated = bool(user.is_authenticated) should do the trick.

    It looks like is_authenticated is a lazily evaluated value, or something odd which is trying to enable both a property getter and a method call on the same property. In effect, the JSON serialiser doesn't know to derive a primitive value from CallableBool instances.

  2. wx2228 commented on Jul 6, 2017

    @wx2228
    Author

    thanks!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions