JSON views

Views

JSONView

class flask_views.json.JSONView

View class for rendering JSON responses.

This class inherits from:

Example usage:

class ExampleJSONView(JSONView):
    pass

Requesting '/users/john/' with the URL route '/users/<user>/' will then result in the following JSON data:

{
    "params": {
        "user": "john"
    }
}

Probably you want to override the get_context_data() method, to provide your own set of data that will be JSON encoded.

get(*args, **kwargs)

Render the JSON response on GET request.

The keyword-arguments passed by the URL dispatcher are added to the context data.

Returns:Output of JSONResponseMixin.render_to_response().
get_context_data(**kwargs)

Get context data for rendering the JSON response.

Returns:A dict containing the following keys:
params
A dict containing the kwargs.

Mixin

JSONResponseMixin

class flask_views.json.JSONResponseMixin

Mixin class for rendering JSON responses.

encoder_class = None

Set this to your custom implementation of json.JSONEncoder if needed. Optional.

render_to_response(context_data={})

Render JSON response for the given context data.

Parameters:context_data – A dict containing the context data. Optional.
Returns:Output of flask.current_app.response_class() containing the JSON dump with 'application/json' mimetype.

Table Of Contents

Related Topics

This Page