Help me solve the code

0 votes

Hello everyone, I train to create a website with Flask and Python. I have setup db and this is the code for my login information:

@app.route('/login/', methods=["POST","GET"])
def loginpage():
message=""
c, conn = connection()
try:
if request.method=="GET":
return render_template("login.html",message=message)
if request.method=="POST":
data=c.execute("SELECT * FROM user WHERE username = '%s'"%(request.form['username']) )
data=c.fetchone()[2]

if data==request.form['password']:
message = "Success"
session['loged-in']=True
session['username']="flag{lollellul}"
return rendertemplate("login.html",message=message) else : message ="Unknown user" return rendertemplate("login.html",message=message)
except Exception as e:
message=str(e)
return render_template("login.html", message=message)

But when I test it, it always returns the error. The 'NoType' object does not have the 'getitem' attribute I edited, but it is still not better
Can anybody help me with it to get?

Jan 9 in Python by krrish
• 160 points

edited Mar 12 by Omkar 49 views

Is this the complete code? The error says:

The 'NoType' object does not have the 'getitem' attribute

But I can not see getitem being used anywhere in the code.  

2 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
+1 vote

The fetchone() method fetches the result of the query one row at a time. When there are no more rows to fetch, it retrieves None. So, while implementing a fetchone() method, it is suggested to use an if condition right after fetching. Try this:

c.execute("SELECT * FROM user WHERE username = '%s'"%(request.form['username']) )
fetch_result=c.fetchone()
if fetch_result:    
  data = fetch_result[2]
    #Here goes rest of the logic
answered Jan 9 by Omkar
• 65,850 points
0 votes
Well thank you, I found a way from your comments
answered Jan 19 by krrish
• 160 points
Glad it helped :)

Related Questions In Python

0 votes
1 answer

Can you help me understand the Global Interpreter Lock in Python

Suppose you have multiple threads which don't really touch ...READ MORE

answered Nov 23, 2018 in Python by ariaholic
• 7,320 points
36 views
0 votes
1 answer
0 votes
1 answer

Need help writing a dataframe into a csv with the help of a loop

Using the following logic you can arrive ...READ MORE

answered Apr 17, 2018 in Python by anonymous
607 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
25 views
+4 votes
6 answers
0 votes
1 answer

How to solve indentation in the below code?

Python does not use brackets, it uses ...READ MORE

answered Feb 9 in Python by Omkar
• 65,850 points
8 views
0 votes
1 answer

Need help understanding python code

In this particular code, I think you ...READ MORE

answered Feb 19 in Python by Omkar
• 65,850 points
33 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.