I used flask to build a mini server on heroku. The server side code looks something like this:
from flask import Flask
from flask_cors import CORS, cross_origin
app = Flask(__name__)
schedule = {'Basketball': 'old value'}
@app.route("/")
@cross_origin()
def get_all_schedule():
return json.dumps(schedule)
@app.route("/update", method=['post'])
def update_basketball_schedule():
globle schedule
schedule['Basketball'] = 'new value'
if __name__ == "__main__":
app.run(host='0.0.0.0')
I have one global dictionary 'schedule' to store the schedule data. I use the post url to update this schedule, and use the "/" url to get the data, seems pretty straight forward.
I am testing this application on my Chrome browser. I called the post url once. And then When I calling "/", sometimes it returns the dictionary with "new value" and sometimes it returns the the dictionary with "old value". What is the reason for this behavior?
I am using a free dyno on heroku. in my Procfile:
web: gunicorn server:app
Aucun commentaire:
Enregistrer un commentaire