[問題] 關於 Flask 奇怪問題

作者: herbacin (herbacin)   2015-11-13 23:49:49
python : 3.5
剛碰Flask, 抱歉有兩個問題想請問一下各位,
問題1
app = Flask(__name__)
def mailDemo():
mailDemo = MailDemo()
r = mailDemo.send_MailDemo()
return r
我改成以下就正常
def mailDemo():
mailDemo = MailDemo()
return mailDemo.send_MailDemo()
就會報 View function did not return a response錯誤
問題2, 當我輸入localhost/Redirect 想顯示 error.html, 用轉址的方式,
但我這樣寫一樣會出現View function did not return a response錯誤
@app.route('/Redirect')
def demoRedirect():
return redirect(url_for('Errorno'))
@app.route('/Errorno')
def errorno():
return render_template('error.html')
非常感謝 ~
作者: ccwang002 (亮)   2015-11-14 00:25:00
問題一的 send_MailDemo() 回傳的東西是什麼啊?mailDemo() function 是怎麼被用在 view 當中的?問題二 url_for() 裡面要放 function name 不是URL路徑所以這個例子應該放 url_for('.errorno') . 可省略
作者: herbacin (herbacin)   2015-11-14 00:34:00
問題一 : 回傳的是字串... 就測試兩個字問題二解決了 謝謝XD一二皆解決了... 問題一測了結果似乎沒有問題 謝謝

Links booklink

Contact Us: admin [ a t ] ucptt.com