Flask应用程序在本地工作,但不在Heroku上(不允许使用方法)

时间:2017-06-28 20:36:57

标签: python heroku flask

当我在本地运行时,我的python代码工作正常,但是当我点击表单上的提交按钮时,Heroku就失败了,我收到错误:方法不允许请求的URL不允许使用该方法。

from flask import Flask, render_template, request, redirect
import dill

app = Flask(__name__)

@app.route('/',methods=['GET','POST'])
def main():
  return redirect('/index')

@app.route('/index',methods=['GET','POST'])
def index():
    message = '  '
    if request.method == 'GET':
        return render_template('index.html',output=message)
    elif request.method == 'POST':
      gender = request.form.get('sex')
      poverty = request.form.get('poverty')
      school = request.form.get('school')
      marital = request.form.get("marital")
      race = request.form.get("race")
      orient = request.form.get("orient")
      phys = request.form.get("phys")
      drinks = request.form.get("drinks")
      age = request.form.get("age")
      message = '  '
      output = get_risk([phys,orient,school,drinks,race,poverty,marital,gender,age])
      if output ==0:
        message = "Not At Risk"
      elif output == 1:
        message = "At Risk!"
      return render_template('index.html',output=message)

def get_risk(features):
  forest = dill.load(open('forest.pkd','rb'))
  return forest.predict(features)

有什么建议吗?

2 个答案:

答案 0 :(得分:0)

浏览器中的“不允许使用方法”很常见,并没有真正告诉您 - 这是一种隐藏错误详细信息的方法,这些用户不应该看到您的代码或了解您的应用程序的详细信息。尝试使用heroku日志来获取更详细的报告。即使heroku日志说我的应用程序在heroku上运行,我也得到了同样的错误

答案 1 :(得分:0)

3 年零 8 个月后看到这个。我只是先创建了应用程序并测试了 heroku 创建的默认页面,但我得到了这种方法不被允许。我的问题是使用了错误的链接。 git.heroku.com/yourapp.git 给出了这个错误。但是 yourapp.herokuapp.com/ 链接有效。同样,这只是使用默认页面。

如果您部署了应用程序并且错误存在于正确的 URL 中,您可能会看到一个应用程序错误页面,并且如前所述,您需要利用其仪表板上的 heroku 日志来解决这些问题。

相关问题