如何在烧瓶中检查多个无线电输入值?

时间:2018-01-25 10:09:55

标签: python flask

我正在制作一个测验应用。我希望在提交表单后发回已检查的无线电输入的值。如何以dict格式发送值。像这样:{1:A,2:B ......}

FLASK

app.route('/test', methods=['GET','POST'])
@is_logged_in
def test():
if request.method == 'POST':
    app.logger.info(request.form)//What to do  here?
#create cursor
cur=mysql.connection.cursor()
cur.execute("SELECT * FROM questions")
data = cur.fetchall()
return render_template('quiz.html', data=data)

HTML

  <form action="" class="text-left ml-4" method="POST">
  {% for i in data %} 
     <h5>{{i['id']}}. {{i['question']}}</h5>
     <div class="form-check">
       <label class="form-check-label">
        <input class="form-check-input" type="radio" name="option" value="A" 
          > {{i['chA']}}
        </label>
     </div>
    <div class="form-check">
     <label class="form-check-label">
       <input class="form-check-input" type="radio" name="option" value="B">{{i['chB']}}
    </label>
      </div>
      <div class="form-check">
          <label class="form-check-label">
            <input class="form-check-input" type="radio" name="option" value="C" > {{i['chC']}}
    </label>
</div>
  <div class="form-check">
     <label class="form-check-label">
        <input class="form-check-input" type="radio" name="option" value="D" > {{i['chD']}}
    </label>
   </div>
 <br>
 {% endfor%}
 <div class="col-md-12 text-center mb-1"> 
<button  type="submit" class="btn-new  btn-lg">  Submit   </button> 

0 个答案:

没有答案