在我保存文件后,即使打开了调试模式,服务器似乎也未检测到对application.py文件所做的更改。我能够看到更改的唯一方法是退出服务器并使用flask run
这是application.py的代码:
import os
import requests
from flask import Flask, session, render_template, request, url_for, flash, redirect, jsonify
from flask_socketio import SocketIO, emit
app = Flask(__name__)
app.config["SECRET_KEY"] = 'secret!'
socketio = SocketIO(app)
@app.route("/")
def index():
print('hello world')
return 'hello!'
if __name__ == '__main__':
socketio.run(app, debug=True)
这是命令行/终端:
λ flask run
* Serving Flask-SocketIO app "application.py"
* Forcing debug mode on
* Restarting with stat
* Debugger is active!
* Debugger PIN: 156-884-244
(3824) wsgi starting up on http://127.0.0.1:5000
(3824) accepted ('127.0.0.1', 50569)
127.0.0.1 - - [10/Sep/2018 20:07:40] "GET /socket.io/?EIO=3&transport=polling&t=1536624459432-5 HTTP/1.1" 200 381 0.000000
(3824) accepted ('127.0.0.1', 50571)
127.0.0.1 - - [10/Sep/2018 20:07:40] "GET /socket.io/?EIO=3&transport=polling&t=1536624460314-6&sid=79eb8e587f664e3383c946bb046717ca HTTP/1.1" 200 215 0.000000
(3824) accepted ('127.0.0.1', 50568)
127.0.0.1 - - [10/Sep/2018 20:07:44] "GET /socket.io/?EIO=3&transport=websocket&sid=79eb8e587f664e3383c946bb046717ca HTTP/1.1" 200 0 4.610168
hello world
127.0.0.1 - - [10/Sep/2018 20:07:44] "GET / HTTP/1.1" 200 152 0.000000
hello world
127.0.0.1 - - [10/Sep/2018 20:07:58] "GET / HTTP/1.1" 200 152 0.000000
hello world
127.0.0.1 - - [10/Sep/2018 20:08:06] "GET / HTTP/1.1" 200 152 0.000000
wsgi exiting
(3824) wsgi exited, is_accepting=True
每次我更改hello world
中的文本并刷新浏览器时,都会显示print('hello world')
中的命令。无论我将其更改为什么,我总是会得到代码的print参数的原始版本。
耦合我注意到的事情:
答案 0 :(得分:1)
嗯。看起来重新加载程序无法与您一起通过flask run
运行该应用程序。但是,当您通过运行应用程序文件(即python application.py
)运行它时,它确实可以工作。
我将记录一个错误并进行调查。