作者herbacin (herbacin)
看板Python
标题[问题] 关於 Flask 奇怪问题
时间Fri Nov 13 23:49:49 2015
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://webptt.com/cn.aspx?n=bbs/Python/M.1447429791.A.1E5.html
1F:→ ccwang002: 问题一的 send_MailDemo() 回传的东西是什麽啊? 11/14 00:25
2F:→ ccwang002: mailDemo() function 是怎麽被用在 view 当中的? 11/14 00:26
3F:→ ccwang002: 问题二 url_for() 里面要放 function name 不是URL路径 11/14 00:32
4F:→ ccwang002: 所以这个例子应该放 url_for('.errorno') . 可省略 11/14 00:34
5F:→ herbacin: 问题一 : 回传的是字串... 就测试两个字 11/14 00:34
6F:→ herbacin: 问题二解决了 谢谢XD 11/14 00:37
7F:→ herbacin: 一二皆解决了... 问题一测了结果似乎没有问题 谢谢 11/14 00:40