flask编写html显示request,html - Python Flask POST/GET request - Stack Overflow

I need help with user authentication in my website. I am using python flask, sqlite3 and DB Browser for SQLite. I'm having trouble with the login part. Each time I try to login and redirect to an html website it says error 404.

Here is the code for the login page:

PackageDrop Login

Username:

Password:

The page that is forwarded to is just simple html, nothing special so I am not uploading it.

If you feel like you need more information to understand, ask and I will post quickly.

Thanks for all the help I get.

EDIT1:

Changed in the login.html the form action from "login.html" to "login" and now it gives a 400 Bad Request error.

EDIT2:

The redirection works. I have changed the code for the login but it makes this error: "ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 7812 and this is thread id 7388". The only thing that I did is just connect to the database like this:

conn = sqlite3.connect('database.db')

This is the new code for the login:

@app.route('/login', methods=['GET', 'POST'])

def login():

error = None

checkP = conn.execute('select pword from users where uname = request.form[\'username\']')

arrayCheck = checkP.fetchall()

if request.method == 'POST':

if request.form['password'] != arrayCheck[[0][0]]:

error = 'Incorrect password'

return redirect(url_for('login.html'))

elif len(arrayCheck) == 0:

error = 'Username or password is incorrect'

return redirect(url_for('login.html'))

else:

session['logged_in'] = True

flash('You are logged in')

return redirect(url_for("userpage"))

return render_template('login.html')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值