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

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

如何從函數(shù)外部使用 flask 變量以便以后在 javascript 中使用?

如何從函數(shù)外部使用 flask 變量以便以后在 javascript 中使用?

ibeautiful 2023-02-22 15:46:22
運(yùn)行 routes.py@app.route('/articles', methods=['GET', 'POST'])def articles():    upload()    return render_template('articles.html')而這個(gè)保存圖像并處理其信息的功能def upload():    if request.method == 'POST':        # Save the file to static/uploads            label = "some string from process above"        probability = "another string"        return None    return None如何在渲染模板時(shí)使用變量標(biāo)簽和概率?有些人使用接近于:return render_template('articles.html', label=label, probability=probability)這樣做是為了使用 js 引用變量。但是,如果它是在 upload() 內(nèi)部計(jì)算的,我該如何引用該變量?需要全局變量嗎?
查看完整描述

1 回答

?
慕慕森

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

您可以從函數(shù)返回這些變量。


您必須解壓縮從函數(shù)發(fā)送的變量upload。


首先,您必須將它們從 退回upload,然后將其拆包發(fā)送到render_template。


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

def articles():

    label, probability = upload()

    return render_template('articles.html', label=label, probability=probability)

def upload():

    if request.method == 'POST':

        # Save the file to static/uploads

    

        label = "some string from process above"

        probability = "another string"


        return (label, probability)


    return (None, None)


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

添加回答

舉報(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)