烧瓶中不允许的方法

时间:2017-03-01 11:48:47

标签: html python-3.x flask

我有一个这样的表格:当我发布细节时,它应该能够将它存储在excel表中。

  <div class="for" align="middle">
    <form action="/models" method="POST">
      <label for="fname">Customer Name</label></br>
      <input type="text" id="Cname" name="Cname" placeholder="Your name.."></br>

      <label for="cname">Customer Email id</label></br>
      <input type="text" id="mailid" name="mailid" placeholder="Your  email id.."></br>

      <label for="cnumber">Customer Contact Number</label></br>
      <input type="text" id="cnumber" name="cnumber" placeholder="Your phone number.."></br>

      <label for="plan">When do you plan to buy ?</label></br>
      <select id="plan" name="plan">
        <option value="Immediate">Immediate</option>
        <option value="1-3 Months">1-3 Months</option>
        <option value="4-6 Months">4-6 Months</option>
      </select>
        </br>
      <label for="spn">Sales Person Name</label></br>
      <input type="text" id="spn" name="spn" placeholder="Sales-person name.."></br>

      <input type="submit" value="Submit">
    </form>
  </div>

我的烧瓶代码是:

@app.route('/cc' ,methods = ['POST', 'GET'])
def cc():
    if request.method=='POST':
        def data():
            wb = openpyxl.load_workbook(url_for('customer_info.xlsx'))
            sheet = wb.active
            sheet = wb.get_sheet_by_name('info')
            print('hey')
            sheet[A2]= request.form['Cname']
            sheet[A3]= request.form['mailid']
            print('hello')
            sheet[A3]= request.form['cnumber']
            sheet[A4]= request.form['plan']
            sheet[A5]= request.form['spn']
            wb.save('customer_info.xlsx')
    return render_template('cc.html')


@app.route('/models' )
def models():
    return render_template('models.html')

我在运行此代码时没有填写excel表。

2 个答案:

答案 0 :(得分:0)

我想你无法看到&#39;嘿嘿&#39;并且&#39;你好&#39;在终端。您的问题是您定义了&#34; 数据&#34;功能,但你不执行它。

将cc路线更改为:

@app.route('/cc' ,methods = ['POST', 'GET'])
def cc():
    if request.method=='POST':
        def data():
            wb = openpyxl.load_workbook(url_for('customer_info.xlsx'))
            sheet = wb.active
            sheet = wb.get_sheet_by_name('info')
            print('hey')
            sheet[A2]= request.form['Cname']
            sheet[A3]= request.form['mailid']
            print('hello')
            sheet[A3]= request.form['cnumber']
            sheet[A4]= request.form['plan']
            sheet[A5]= request.form['spn']
            wb.save('customer_info.xlsx')
        data()
    return render_template('cc.html')

答案 1 :(得分:0)

您的表单已发布到/models

<form action="/models" method="POST">

但您的/models路由不接受POST作为方法,并且不与Excel工作表交互。

@app.route('/models' )
def models():
    return render_template('models.html')

我认为您要张贴到/cc而不是/models

此外,在cc路由中,您正在定义一个名为data的函数,但不会调用该函数。您可以将该路线更改为:

@app.route('/cc' ,methods = ['POST', 'GET'])
def cc():
    if request.method=='POST':
        wb = openpyxl.load_workbook(url_for('customer_info.xlsx'))
        sheet = wb.active
        sheet = wb.get_sheet_by_name('info')
        print('hey')
        sheet[A2]= request.form['Cname']
        sheet[A3]= request.form['mailid']
        print('hello')
        sheet[A3]= request.form['cnumber']
        sheet[A4]= request.form['plan']
        sheet[A5]= request.form['spn']
        wb.save('customer_info.xlsx')
    return render_template('cc.html')