gpt4 book ai didi

python - 使用python bottle发布用户名和密码

转载 作者:太空宇宙 更新时间:2023-11-04 05:47:37 25 4
gpt4 key购买 nike

我正在学习 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>"

关于python - 使用python bottle发布用户名和密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31577865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com