Пример #1
0
def make_response(data, code, http_code=200):
    data = dict(error=dict(code=code.get('code'),
                           http_code=http_code,
                           description=code.get('description')),
                result=data)
    response = flask_make_response(json.dumps(data, indent=4), http_code)
    response.headers['Content-Type'] = 'application/json; charset=utf-8'
    return add_cross_domain_headers(response)
Пример #2
0
def make_response(*args, **kwargs):
    """
    Customized flask-restful make_response
    """
    response = flask_make_response(*args, **kwargs)
    if request.is_jsonapi:
        # Only use "application/vnd.api+json" if the client sent this with the request
        response.headers["Content-Type"] = "application/vnd.api+json"
    return response
Пример #3
0
def jsonify_status_code(status_code, *args, **kw):
    """Returns a jsonified response with the specified HTTP status code.

    The positional and keyword arguments are passed directly to the
    :func:`flask.jsonify` function which creates the response.
    """
    is_batch = kw.pop('is_batch', False)
    if is_batch:
        response = flask_make_response(json.dumps(*args, **kw))
        response.mimetype = 'application/json'
        response.status_code = status_code
        return response
    response = jsonify(*args, **kw)
    response.status_code = status_code
    return response
Пример #4
0
def jsonify_status_code(status_code, *args, **kw):
    """Returns a jsonified response with the specified HTTP status code.

    The positional and keyword arguments are passed directly to the
    :func:`flask.jsonify` function which creates the response.
    """
    is_batch = kw.pop('is_batch', False)
    if is_batch:
        response = flask_make_response(json.dumps(*args, **kw))
        response.mimetype = 'application/json'
        response.status_code = status_code
        return response
    response = jsonify(*args, **kw)
    response.status_code = status_code
    return response
Пример #5
0
def intro():
    resp = flask_make_response(render_template('index.html', intro=True))
    resp.set_cookie('intro', '1')
    return resp
Пример #6
0
def make_response(message, status):
    response = flask_make_response(message, status)
    return response
Пример #7
0
def intro():
    resp = flask_make_response(render_template('index.html', intro=True))
    resp.set_cookie('intro', '1')
    return resp