【问题标题】:Flask route template烧瓶路线模板
【发布时间】:2019-12-30 09:30:39
【问题描述】:

当我路由我的烧瓶应用程序时,我收到了错误的请求。但我不明白为什么我不能渲染我的 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

【问题讨论】:

    标签: python html flask


    【解决方案1】:

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

    @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')
    

    【讨论】:

      【解决方案2】:
      @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 不对,需要返回请求

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-03
        • 2015-07-16
        • 1970-01-01
        • 2022-11-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多