sudhar chrome
sudhar chrome

Reputation: 75

TypeError: render_template() takes 1 positional argument but 2 were given in (Flask Framework)

kindly help it out folks! I am new to programming. I am trying to Authenticate Login. But its showing "TypeError....." i couldn't figure out.

See Below This is My code (main.py)

 @app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'POST':
        email = request.form.get('EMAIL')
        con1 = sqlite3.connect("check10.db")
        cur = con1.cursor()
        data = cur.execute("SELECT EMAIL FROM register WHERE EMAIL = ? ", (email,))
        if data == email:
            return render_template('homepage.html')
        else:
            alert = "Check Credentials "
            return render_template('loginpage.html', alert)
    return render_template("loginpage.html")

Upvotes: 0

Views: 553

Answers (2)

Federico Baù
Federico Baù

Reputation: 7735

Try this:

 from flask import request, render_template, flash

 @app.route('/', methods=['GET', 'POST'])
 def index():
     if request.method == 'POST':
         email = request.values.get('EMAIL')
         con1 = sqlite3.connect("check10.db")
         cur = con1.cursor()
         data = cur.execute("SELECT EMAIL FROM register WHERE EMAIL = ? ", (email,))
         if data == email:
             return render_template('homepage.html')
         else:
             flash('Check Credentials ')
             return render_template('loginpage.html')
  return render_template("loginpage.html")

Try also to change the variable email like:

email = request.args.get('EMAIL')

Upvotes: 1

Mayur Deshmukh
Mayur Deshmukh

Reputation: 392

You are getting error because of return render_template('loginpage.html', alert).

If you want to send some data from server to HTML page then you can refer to link.

If you want flash message 'check credentials' to the user then refer to this Link

Upvotes: 1

Related Questions