烧瓶路线模板

时间:2019-12-30 09:30:39

标签: python html flask

当我路由烧瓶应用程序时,我收到了错误的请求。但是我不明白为什么我不能渲染我的html模板。

这是我的应用路由代码:

@app.rout('/', methods=['POST', 'GET'])
def main_page():
    return render_template('sign.html')

@app.route('/sign', methods=['POST', 'GET'])
def SignResource():
    data = {
    "amount": request.form['amount'],
    "payway": request.form['payway'],
    "description": request.form['description']
    }

这是我的模板表格:

<form action = "http://localhost:5000/sign" method = "post">
          <div class="pay_info">
              <input type="text", name='amount', value="12.34">
              <input list="currency_list" name="payway" autofocus>
              <datalist id="currency_list"  >
                  <option value="RUB">
                  <option value="USD">
                  <option value="EUR">
             </datalist>
          <div class='description_text'>
              <input type="text", name='description', value='Test description'>
         </div>
         <input type="submit">
      </form>

在模板中,我以html形式写入数据,然后在“ / sign”路由中对其进行了解析。 但是当我尝试呈现我的html时,我得到了代码400

2 个答案:

答案 0 :(得分:0)

以下代码中的路线拼写错误:

@app.rout('/', methods=['POST', 'GET'])
def main_page():
    return render_template('sign.html')

更正它:

@app.route('/', methods=['POST', 'GET'])
def main_page():
    return render_template('sign.html')

答案 1 :(得分:0)

@app.route('/', methods=['POST', 'GET'])
def main_page():
    return render_template('sign.html')

@app.route('/sign', methods=['POST', 'GET'])
def SignResource():
    data = {
    "amount": request.form['amount'],
    "payway": request.form['payway'],
    "description": request.form['description']
    }
    return "ok"

函数名称rout不正确,需要返回请求