亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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

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

ibeautiful 2023-02-22 15:46:22
運行 [email protected]('/articles', methods=['GET', 'POST'])def articles():    upload()    return render_template('articles.html')而這個保存圖像并處理其信息的功能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如何在渲染模板時使用變量標簽和概率?有些人使用接近于:return render_template('articles.html', label=label, probability=probability)這樣做是為了使用 js 引用變量。但是,如果它是在 upload() 內部計算的,我該如何引用該變量?需要全局變量嗎?
查看完整描述

1 回答

?
慕慕森

TA貢獻1856條經驗 獲得超17個贊

您可以從函數返回這些變量。


您必須解壓縮從函數發送的變量upload。


首先,您必須將它們從 退回upload,然后將其拆包發送到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)


查看完整回答
反對 回復 2023-02-22
  • 1 回答
  • 0 關注
  • 139 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號