首页 > 解决方案 > 如何在从 python Flask 服务器获取的 expo react-native 应用程序上显示图像

问题描述

从我的 expo 应用程序中,我想向服务器发出请求。代码如下所示:

fetch('http://caiofernandes.pythonanywhere.com/')
          .then(res => {
            console.log(res)
          })
         .catch(error => console.log(error))

我的烧瓶服务器应该以图像响应。

from flask import Flask
from flask_cors import CORS, cross_origin
from flask import send_file

app = Flask(__name__)
CORS(app)

@app.route('/')
@cross_origin()
def hello_world():
    return send_file('test100.png',  mimetype='image/png')

如何显示我的服务器返回的图像?

标签: pythonreact-nativeflaskfetchexpo

解决方案


推荐阅读