RubyJ
RubyJ

Reputation: 305

Returning multiple values in a FLASK response

I have a FLASK response object that I am preparing with two string values as follows:

vioAllScript = encode_utf8(vioAllScript)
vioAllDiv = encode_utf8(vioAllDiv)
vioTup = (vioAllDiv, vioAllScript,)

resp = make_response(vioTup)
return resp

However, whenever I retrieve this response on the front end, the second value always get trimmed out of the response leaving only the first value. I have tried other options such as resp = make_response(vioAllDiv, vioAllScript) but the same thing always happens. Is there a way to get my response to contain two string values without concatenating them together?

Upvotes: 4

Views: 7051

Answers (1)

wim
wim

Reputation: 362627

Those flask interfaces are a bit too overloaded, which can be confusing. In the face of ambiguity, unfortunately, flask does not refuse the temptation to guess. If you dig into the relevant section of the docs you will find this part for calling make_response with a tuple:

Either (body, status, headers), (body, status), or (body, headers)

The second element of the tuple was not being interpreted as part of the response body.

Consider returning something like this instead:

flask.jsonify(vioAllDiv=vioAllDiv, vioAllScript=vioAllScript)

Upvotes: 5

Related Questions