How to respond to a boolean type in sanic?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How to respond to a boolean type in sanic?



I need to respond directly to True or False. How can I do this? Json, text, raw.... can't
code


if param == signature:
return True
else:
return False



Error


File "/usr/local/lib/python3.5/dist-packages/sanic/server.py", line 337, in
write_response
response.output(
AttributeError: 'bool' object has no attribute 'output'




1 Answer
1



I think what you are looking for is something like this:


from sanic import responses

@app.get('/myroute')
async def myroute(request):
output = True if param == signature else False
return response.json(output)



You just need to wrap your response in response.json.


response.json






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results