看板 Python 關於我們 聯絡資訊
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') 非常感謝 ~ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.34.181.227 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1447429791.A.1E5.html
ccwang002: 問題一的 send_MailDemo() 回傳的東西是什麼啊? 11/14 00:25
ccwang002: mailDemo() function 是怎麼被用在 view 當中的? 11/14 00:26
ccwang002: 問題二 url_for() 裡面要放 function name 不是URL路徑 11/14 00:32
ccwang002: 所以這個例子應該放 url_for('.errorno') . 可省略 11/14 00:34
herbacin: 問題一 : 回傳的是字串... 就測試兩個字 11/14 00:34
herbacin: 問題二解決了 謝謝XD 11/14 00:37
herbacin: 一二皆解決了... 問題一測了結果似乎沒有問題 謝謝 11/14 00:40