#๐ TypeError: The view function did not return a valid response. The return type must be a string, di
16 messages ยท Page 1 of 1 (latest)
@tranquil marsh
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Because you're returning an image, that's why
Try responding with the image URL inside a dictionary
You do have it saved with img.save
Since its saved, you can return with the image url of where its saved.
Normally stored in a static folder for CDN to process
Its either that or use the send_file
As an example, this URL:
http://example.com/get_image?type=1
should return a response with a image/gif MIME type. I have two static .gif images,
and if type is 1, it should return ok.gif, else re...
what did you change?
Show your latest code
is the img the filename?
If you look at the answer from SO:
from flask import send_file
@app.route('/get_image')
def get_image():
if request.args.get('type') == '1':
filename = 'ok.gif'
else:
filename = 'error.gif'
return send_file(filename, mimetype='image/gif')
filename is the name of the image file.
Did you also change it so its saved and used the image file name too?
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.