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

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

flask url_for 在js 中 如果正確傳多個參?

flask url_for 在js 中 如果正確傳多個參?

守候你守候我 2019-09-19 22:50:30
$(function(){...content=$('#search_input').val();type=$('#search_select').val();url="{{url_for('search',type="+type+",content="+content+")}}...})@app.route('/search/type//content/')defsearch(type,content):return'ok'第二點js代碼中,url的值并獲取不到,請問如何正確傳參數給url_for?
查看完整描述

2 回答

?
智慧大石

TA貢獻1946條經驗 獲得超3個贊

暫時換了個方法用動態的url
@app.route('/search/')
defsearch(type,content):
//request.args.get接受參數
return'ok'
//js代碼
my_url="{{url_for('search')}}";
console.log(my_url)
my_url_full=my_url+"?type="+type+"&content="+content
console.log(my_url_full)
                            
查看完整回答
反對 回復 2019-09-19
?
一只甜甜圈

TA貢獻1836條經驗 獲得超5個贊

舉個例子
@app.route('/')
defindex():
returnrender_template('index.html')
index.html如下
home
當調用render_template方法時,就已經是在渲染html模板了,這個過程是在服務端進行的,會把url_for的結果渲染成對應的路由,然后再返回給瀏覽器。
針對你上述的操作
$(function(){
...
content=$('#search_input').val();//1
type=$('#search_select').val();//2
url="{{url_for('search',type="+type+",content="+content+")}}"http://3
...
})
這段JS是在瀏覽器執行的,1和2都是動態獲取的結果,3的值已經是/search/type//content/,所以無法獲取你想要的結果。
                            
查看完整回答
反對 回復 2019-09-19
  • 2 回答
  • 0 關注
  • 979 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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