我当前正在尝试登录网络应用程序时执行提取请求,但是我一直收到。
87466804-e84d-413e-abd1-74dc56624149-ide.cs50.xyz/sell:1 Failed to load resource: the server responded with a status of 502 (Bad Gateway)
然后
sell:1 Access to fetch at 'http://87466804-e84d-413e-abd1-74dc56624149-ide.cs50.xyz/sell' from origin 'http://127.0.0.1:5000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
我的Flask应用看起来像
@app.route("/sell", methods=["GET", "POST"])
@login_required
def sell():
ticker_symbols = helper_index.get_ticker_symbols(currently_owned_table)
#handles GET request
if request.method == "GET":
return render_template("sell.html", companies=ticker_symbols)
if request.method == "POST":
#handles submitted form
if "sell_form" in request.form:
#if form is submitted
return "thanks"
#handles fetch request
else:
the_request = request.get_json()
the_symbol = [the_request["symbol"]]
shares_available = helper_index.get_total_shares(the_symbol, currently_owned_table)
requested_shares = the_request["shares"]
print(requested_shares)
if int(requested_shares) <= shares_available[0]:
return "true"
else:
return "false"
我不确定该如何解决?和想法得到赞赏
答案 0 :(得分:0)
Flask-CORS做魔术。
app.py :
app = Flask(__name__)
cors = CORS(app, resources={r"/*": {"origins": "*"}})
@app.route("/api/v1/users")
def list_users():
return "user example"