问题描述
无论我做什么,我都无法弄清楚这一点。无论间距如何,我都会不断收到意外缩进错误。我花了两天时间自己修复它,并找到可以解释发生情况的人。我包括了CS50 IDE的屏幕截图,因为我觉得它最好地显示了我遇到的错误。
@app.route("/sell",methods=["GET","POST"])
@login_required
def sell():
if request.method == "POST":
quote=lookup(request.form.get("symbol"))
if quote == None:
return apology ("invalid symbol",400)
try:
shares=int(request.form.get("shares"))
except:
return apology("shares must be positive",400)
解决方法
您需要使用try
“关闭” except
块,即:
try:
shares=(int(request.form.get("shares"))
except Exception as err:
print(err)
或跳过try
,并使用try-except,当您知道预期的错误类型时,即:
shares=(int(request.form.get("shares"))
有关tr除外块here
的更多信息所以关于缩进的错误也是令人误解的,(: