简体   繁体   中英

cs50 src5 example webpage not responding

i am currently doing the cs50 web programing course an am trying out some of the examples from lecture 5. running the example with flask it opens in the browser however when i click the buttons on the webpage the page doesn't update and after a few second delay i get the following output in terminal.

Serving Flask app "application"
Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [21/May/2020 10:04:25] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [21/May/2020 10:04:25] "GET /static/index.js HTTP/1.1" 200 -
127.0.0.1 - - [21/May/2020 10:04:26] "GET /socket.io/?EIO=3&transport=polling&t=1590048266102-0 HTTP/1.1" 200 -
127.0.0.1 - - [21/May/2020 10:04:26] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [21/May/2020 10:05:26] "GET /socket.io/?EIO=3&transport=polling&t=1590048266123-1&sid=36212935b112433793acd64f248b02ee HTTP/1.1" 400 -
127.0.0.1 - - [21/May/2020 10:05:26] "POST /socket.io/?EIO=3&transport=polling&t=1590048267871-2&sid=36212935b112433793acd64f248b02ee HTTP/1.1" 400 -
127.0.0.1 - - [21/May/2020 10:05:26] "POST /socket.io/?EIO=3&transport=polling&t=1590048326147-3&sid=36212935b112433793acd64f248b02ee HTTP/1.1" 400 -
127.0.0.1 - - [21/May/2020 10:05:27] "GET /socket.io/?EIO=3&transport=polling&t=1590048327116-4 HTTP/1.1" 200 -'

this is the flask code i am using

app = Flask(__name__)
app.config["SECRET_KEY"] = os.getenv("SECRET_KEY")
socketio = SocketIO(app)

@app.route("/")
def index():
    return render_template("index.html")

@socketio.on("submit vote")
def vote(data):
    selection = data["selection"]
    emit("announce vote", {"selection": selection}, broadcast=True)

i have tried changing the this line

socketio = SocketIO(app)

to

socketio = SocketIO(app,cors_allowed_origins="http://127.0.0.1:5000")

without any change please can someone assist with this problem the full source file is linked here . and the example i am trying to use is vote0 and vote1.

Reading through countless forums i finally stumbled upon an answer that worked for me. It is as simple as flask run --with-threads instead of the normal flask run

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM