我根据flaskr样本写这个,我可以用浏览器登录,但测试失败。谢谢你的帮助!
@app.route('/login', methods=['GET', 'POST'])
def login():
error = None
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
if lib.authenticate_user(username, password):
session['logged_in'] = True
flash('You were logged in')
return render_template('www.html')
return render_template('login.html', error=error)
tests.py
def login(self, username, password):
#print username, password
return self.app.post('/Login', data=dict(
username=username,
password=password
), follow_redirects=True)
# testing functions
def test_login_logout(self):
"""Make sure login and logout works"""
rv = self.login('c1','123')
assert 'You were logged in' in rv.data
答案 0 :(得分:7)
更改为帖子('/ login',