【发布时间】:2021-06-28 06:06:51
【问题描述】:
我试图从 Python 脚本中获取值,如下所示:
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/', methods = ['GET'])
def index():
return jsonify({"greetings" : "Hi this is Python"})
if __name__ == '__main__':
app.run(debug = True)
在 launichg 得到以下输出后:
C:\Users\finn1\PycharmProjects\FLASK_FLUTTER_APP\venv\Scripts\python.exe C:/Users/finn1/PycharmProjects/FLASK_FLUTTER_APP/main.py
* Serving Flask app "main" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Restarting with stat
* Debugger is active!
* Debugger PIN: ***-***-***
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
我像这样在 Flutter 中导入了 http 库:
import 'package:http/http.dart';
然后我尝试使用“http.get”获取数据:
child: IconButton(
icon: new Icon(
Icons.settings,
),
onPressed: () async {
final response = await http.get("http://127.0.0.1:5000/");
但我在启动我的应用程序时收到以下错误:
Error: The getter 'http' isn't defined for the class '_HomepageState'.
- '_HomepageState' is from 'package:what_todo/screens/homepage.dart' ('lib/screens/homepage.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'http'.
final response = await http.get("http://127.0.0.1:5000/");
感谢您的帮助!
【问题讨论】:
标签: python flutter http http-get