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 in Python by krrish
• 160 points

edited Mar 12 by Omkar 60 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 by Omkar
• 67,620 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,340 points
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
+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 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 275 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
• 67,620 points
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
• 67,620 points