Python (500内部服务器错误)Flask Post请求导致服务器错误[Flask]

Python (500内部服务器错误)Flask Post请求导致服务器错误[Flask],python,html,heroku,flask,Python,Html,Heroku,Flask,我在Heroku上部署了一个简单的flask应用程序(),但它给了我以下错误 Internal Server Error The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application. 当我提交没有任何文件时,它会给我这个错误,但当我提交文件时,它不会

我在Heroku上部署了一个简单的flask应用程序(),但它给了我以下错误

Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
当我提交没有任何文件时,它会给我这个错误,但当我提交文件时,它不会给我这个错误。但问题是,在这两种情况下,我都会返回类似的东西

下面是我的python代码,它给出了错误

@app.route('/', methods = ['GET', 'POST'])
def upload_file_calculate():
   if request.method == 'POST':
      if ('goodsold' not in request.files) or ('costingsheet' not in request.files) :
         return render_template('upload.html')
      good_sold = request.files['goodsold']
      costing_sheet = request.files['costingsheet']
      if good_sold and costing_sheet:
         calc=calc_cogs(good_sold,costing_sheet)
         return render_template('upload.html',COGS=calc.calculate()[0],Profit=calc.calculate()[1],items=calc.calculate()[2])
   else:
      return render_template('upload.html')
这里是我提交post请求的Html代码


销货
成本表
提交

如果request.method==“POST”:如果你有两个
,但是你没有

else: 
    return render_template(..) 
或者至少

return render_template(..) 
因此,它可以运行
并默认返回None

@app.route('/', methods = ['GET', 'POST'])
def upload_file_calculate():
   if request.method == 'POST':
      if ('goodsold' not in request.files) or ('costingsheet' not in request.files) :
         return render_template('upload.html')
      good_sold = request.files['goodsold']
      costing_sheet = request.files['costingsheet']
      if good_sold and costing_sheet:
         calc=calc_cogs(good_sold,costing_sheet)
         return render_template('upload.html',COGS=calc.calculate()[0],Profit=calc.calculate()[1],items=calc.calculate()[2])

      return render_template(...)  # <--- need it instead of default `return None`

   else:
      return render_template('upload.html')

已售出的商品和成本表
条件失败时,没有返回语句
if request.method=='POST':
您有两个
if
但没有
否则:返回渲染模板(…)
或至少
返回渲染模板(…)
因此它可以运行
返回None
作为default@furas太棒了,它成功了!请把你的评论作为答案,这样我就可以接受了!
@app.route('/', methods = ['GET', 'POST'])
def upload_file_calculate():
   if request.method == 'POST':
      if ('goodsold' in request.files) and ('costingsheet' in request.files) :
          good_sold = request.files['goodsold']
          costing_sheet = request.files['costingsheet']
          if good_sold and costing_sheet:
             calc = calc_cogs(good_sold,costing_sheet)
             return render_template('upload.html', COGS=calc.calculate()[0], Profit=calc.calculate()[1], items=calc.calculate()[2])

   return render_template('upload.html')