Jun-13-2020, 04:36 PM
(This post was last modified: Jun-13-2020, 04:37 PM by card51shor.)
OK well I am entering the data. I have a registration code here :
1) When I login with the incorrect username and password - i get an error.
2) When I login with a correct username and incorrect password - it works.
3) When I login with correct username and correct password - it works.
It only doesn't work on the first option when both are wrong - it gives me an error like this :
@app.route("/register", methods=["GET", "POST"]) def register(): if request.method == "GET": return render_template("register.html") elif request.method == "POST": password = request.form.get("password") username = request.form.get("username") session.clear() db.execute("INSERT INTO users (username, password) VALUES (:username, :password)", {"username":username, "password":password}) db.commit() return render_template("login.html")the issue with my app is:
1) When I login with the incorrect username and password - i get an error.
2) When I login with a correct username and incorrect password - it works.
3) When I login with correct username and correct password - it works.
It only doesn't work on the first option when both are wrong - it gives me an error like this :
Error:TypeError
TypeError: 'NoneType' object is not subscriptable
Traceback (most recent call last)
File "C:\Python38\Lib\site-packages\flask\app.py", line 2464, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Python38\Lib\site-packages\flask\app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "C:\Python38\Lib\site-packages\flask\app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Python38\Lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Python38\Lib\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "C:\Python38\Lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Python38\Lib\site-packages\flask\app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Python38\Lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Python38\Lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Python38\Lib\site-packages\flask\app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\school\project1\application.py", line 42, in login
if username is not None and usernamedata[0] == username and passworddata[0] == password:
TypeError: 'NoneType' object is not subscriptable
Here's my code in question: @app.route("/login", methods=["GET","POST"]) def login(): password = request.form.get("password") username = request.form.get("username") usernamedata = db.execute("SELECT username FROM users WHERE username=:username", {"username":username}).fetchone() passworddata = db.execute("SELECT password FROM users WHERE username=:username", {"username":username}).fetchone() if username is not None and usernamedata[0] == username and passworddata[0] == password: print("welcome") return render_template("welcome.html") elif username is not None and (usernamedata[0] != username or passworddata[0] != password): print("no match") return render_template("login.html") else: print("empty") return render_template("login.html")