from flask import make_response
@app.route('/')
def hello():
response = make_response("文本内容!")
response.headers["Content-Type"] = "text/plain;charset=UTF-8"
return response
from flask import make_response
@app.route('/')
def hello():
response = make_response("文本内容!")
# response.headers['Content-Type'] = "text/plain"
response.headers['Content-Disposition'] = "attachment; filename=download.txt"
return response
from io import BytesIO
import numpy as np
import requests
from PIL import Image
from flask import Flask, request, make_response
@app.route("/", methods=["POST", 'GET'])
def search_image():
url = request.args.get("url") or request.form.get("url")
if not url:
response = make_response("OK", 200)
else:
try:
# load image
raw_image_response = requests.get(url=url, timeout=10)
# do something
image = Image.open(BytesIO(raw_image_response.content))
new_image_obj = image
# response
new_image_bytes = BytesIO()
new_image_obj.save(new_image_bytes, 'JPEG')
response = make_response(new_image_bytes.getvalue())
response.headers['Content-Type'] = "image/jpeg"
except Exception as e:
print(e)
response = make_response("error {}".format(e), 200)
return response