Flask实现举牌子的功能

上代码

from flask import Flask,render_template,request,make_response
from flask_cors import CORS,cross_origin
import requests
import urllib

app = Flask(__name__,)
CORS(app, resources=r'/*')

@app.route('/')
def hello_world():
    return "hello world"

@app.route('/image',methods=['GET', 'OPTIONS'])
@cross_origin()
def image():
    word = request.args['word']
    url = "https://www.jiuwa.net/tools/jupai/index.php"
    resp = requests.post(url, data={"t": word})
    my_url = f'https://www.jiuwa.net/{resp.content.decode("utf-8")}'
    image_data = urllib.request.urlopen(my_url).read()
    res = make_response(image_data)
    res.headers['Content-Type'] = 'image/png'
    return res

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0', port=9999)
访问: http://127.0.0.1:9999/image?word=JerryJi

结果如下:

举牌
Demo,点击可测试

你可能感兴趣的:(Flask实现举牌子的功能)