第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何訪問選定的下拉菜單回?zé)?/h1>

我一直在嘗試通過Flask單擊按鈕訪問選定的下拉列表?;谖易隽巳缦碌慕ㄗh之一應(yīng)用程序.py    @app.route('/ra/connect',methods=['GET','POST'])    def connect_management():       user = (request.form['selected_class']).first()       return (str(user))應(yīng)用程序.html              <select name="selected_class" class="form-control" id="all_classes">                  {% for o in all_classes %}                  <option  value="{{ o }}" selected>{{ o }}</option>                  {% endfor %}                 </select> 我需要使用選定的下拉選項(xiàng)并Flask通過單擊按鈕從 api 填充更多結(jié)果并將它們顯示在countdown按鈕下方的標(biāo)記中??偠灾?,我需要在Flask沒有新選項(xiàng)卡的情況下將下拉值訪問回 api。<button class="form-control" id="button" onclick="connect4()">Get gateways</button>                <p id="countdown"></p>我一直在TypeError: 'ImmutableMultiDict' object is not callable即使在遵循建議之后
查看完整描述

1 回答

?
一只甜甜圈

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超5個(gè)贊

我無法通過您的代碼得到您的錯(cuò)誤??赡苣盏讲煌a的錯(cuò)誤,但您沒有顯示可以確認(rèn)它的完整錯(cuò)誤消息。


要在HTML不重新加載頁(yè)面的情況下更新您需要JavaScript或jQuery發(fā)送AJAX請(qǐng)求,獲取響應(yīng)并將其放入現(xiàn)有HTML


最小的工作示例:


from flask import Flask, request, render_template_string


app = Flask(__name__)


@app.route('/')

def index():

    return render_template_string('''<html>

<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>


<form action="/ra/connect" method="POST" id="form">

   <select name="selected_class" class="form-control" id="all_classes">

   {% for o in all_classes %}

      <option  value="{{ o }}" selected>{{ o }}</option>

   {% endfor %}   

   </select> 

   <button class="form-control" id="button">Get gateways</button>

</form>


<p id="countdown"></p>


<script>

    $('#button').click( function(event) {

        event.preventDefault();


        $.post("/ra/connect", $('#form').serialize(), function(data) {

            //alert(data);

            countdown = $("#countdown");

            countdown.append(data + "<br/>");

        });

    });

</script>

</html>''', all_classes=['Hello', 'World'])


@app.route('/ra/connect', methods=['GET', 'POST'])

def connect_management():

    user = request.form.get('selected_class')

    print('user:', user)

    return str(user)


app.run()


查看完整回答
反對(duì) 回復(fù) 2022-10-08
  • 1 回答
  • 0 關(guān)注
  • 141 瀏覽
慕課專欄
更多

添加回答

了解更多

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)