我目前正在研究一个烧瓶和python应用程序:https://getanumber.herokuapp.com/
单击“生成时没有值”时,将显示“内部服务器错误”。
我希望在发生这种情况时打印一条消息。这里到目前为止我得到的是无价值,但它不起作用:
def RandomNumberGenerator():
import random
Min = request.form['Min']
Max = request.form['Max']
xMin = int(Min)
xMax = int(Max)
if xMin > xMax:
return "Min value can not be higher than max value"
elif xMin is None:
return "Precise the min value"
elif xMax is None:
return "Precise the max value"
else:
return str(random.randint(xMin, xMax))
BR
答案 0 :(得分:2)
正如@DeepSpace在他的评论中暗示的那样,你总是需要检查用户输入是否有序(通常称为输入消毒)。
try:
Min = int(request.form['Min'])
Max = int(request.form['Max'])
except ValueError as e:
# Whatever you want to do if you got something other than a number.