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():
c, conn = connection()
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']) )

if data==request.form['password']:
message = "Success"
return rendertemplate("login.html",message=message) else : message ="Unknown user" return rendertemplate("login.html",message=message)
except Exception as 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, 2019 in Python by krrish
• 160 points

edited Mar 12, 2019 by Omkar 145 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.

+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']) )
if fetch_result:    
  data = fetch_result[2]
    #Here goes rest of the logic
answered Jan 9, 2019 by Omkar
• 69,150 points
0 votes
Well thank you, I found a way from your comments
answered Jan 19, 2019 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 aryya
• 7,440 points
0 votes
1 answer
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,249 views
0 votes
0 answers
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
0 votes
1 answer

How to solve indentation in the below code?

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

answered Feb 9, 2019 in Python by Omkar
• 69,150 points
0 votes
1 answer

Need help understanding python code

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

answered Feb 19, 2019 in Python by Omkar
• 69,150 points