使用 python bottle 发布用户名和密码
Posting username and password using python bottle
我正在学习 Bottle,我在他们的网站上看到了登录示例。它看起来像这样:
@route('/login')
def login():
return '''
<form action="/login" method="post">
username: <input name="username" type="text" />
password: <input name="password" type="password" />
<input value="Login" type="submit" />
</form>
'''
@route('/login', method='POST')
def do_login():
username = request.forms.post('username')
password = request.forms.post('password')
if check_login(username, password):
return "<p>You have logged in successfuly</p>"
else:
return "<p>Your log in attempt has failed</p>"
我从代码中看到的是能够输入用户名和密码并看到成功消息或失败消息。但是我一直收到 Internal server error
消息。
我也试过这样做:
if username=='username' and password=='password'
我知道它并不漂亮,但此时我不确定它是如何工作的。这给出了同样的错误。
我离开了它并在工作中而不是在家里尝试了它,并让它与以前的版本一起工作。现在澄清一下代码如下:
@route('/login')
def login():
return '''
<form action="/login" method="post">
username: <input name="username" type="text" />
password: <input name="password" type="password" />
<input value="Login" type="submit" />
</form>
'''
@route('/login', method='POST')
def do_login():
username = request.forms.get('username')
password = request.forms.get('password')
if username==username and password==password
return "<p>You have logged in successfuly</p>"
else:
return "<p>Your log in attempt has failed</p>"
因此将 request.forms.post
更改为 request.forms.get
后来我做了我自己的版本 check_login
:
usernames = ["username", "user"]
passwords = ["password", "pass"]
def check_login(username, password):
if username in usernames and password in passwords:
return True
else:
return False
并将验证更改为:
if check_login(username, password) is True:
return "<p>You have logged in succesfully</p>"
else:
return "<p>Logging in attempt failed</p>"
我正在学习 Bottle,我在他们的网站上看到了登录示例。它看起来像这样:
@route('/login')
def login():
return '''
<form action="/login" method="post">
username: <input name="username" type="text" />
password: <input name="password" type="password" />
<input value="Login" type="submit" />
</form>
'''
@route('/login', method='POST')
def do_login():
username = request.forms.post('username')
password = request.forms.post('password')
if check_login(username, password):
return "<p>You have logged in successfuly</p>"
else:
return "<p>Your log in attempt has failed</p>"
我从代码中看到的是能够输入用户名和密码并看到成功消息或失败消息。但是我一直收到 Internal server error
消息。
我也试过这样做:
if username=='username' and password=='password'
我知道它并不漂亮,但此时我不确定它是如何工作的。这给出了同样的错误。
我离开了它并在工作中而不是在家里尝试了它,并让它与以前的版本一起工作。现在澄清一下代码如下:
@route('/login')
def login():
return '''
<form action="/login" method="post">
username: <input name="username" type="text" />
password: <input name="password" type="password" />
<input value="Login" type="submit" />
</form>
'''
@route('/login', method='POST')
def do_login():
username = request.forms.get('username')
password = request.forms.get('password')
if username==username and password==password
return "<p>You have logged in successfuly</p>"
else:
return "<p>Your log in attempt has failed</p>"
因此将 request.forms.post
更改为 request.forms.get
后来我做了我自己的版本 check_login
:
usernames = ["username", "user"]
passwords = ["password", "pass"]
def check_login(username, password):
if username in usernames and password in passwords:
return True
else:
return False
并将验证更改为:
if check_login(username, password) is True:
return "<p>You have logged in succesfully</p>"
else:
return "<p>Logging in attempt failed</p>"