When i am using username from config.json file in python flask i am able to create session but when i am importing name from database I fail to do so

Viewed 33
        if (username==aname or username==aemail) and userpass==apass:
            session['user'] = username
            print("hello")
            poste = classic.Posts.query.filter_by(user_id="1").all()
            posts = classic.Posts.query.all()
            return render_template('dashboard.html', params=params, posts=posts, poste=poste)




 #if username == params['admin_user'] and userpass == params['admin_password']:
         #   session['user'] = username
          #  poste = classic.Posts.query.filter_by(user_id="1").all()
           # posts = classic.Posts.query.all()
            #return render_template('dashboard.html', params=params, posts=posts, poste=poste)

while using first section i am not able to create session as using name from database but while using 2nd section able to create session as using name from config. json file. i am doing in python flask

1 Answers

You are calling "params" which is not defined. THis is likely resulting in a WSGI exception and causing the login to fail. Try below

if (username==aname or username==aemail) and userpass==apass:
            session['user'] = username
            print("hello")
            poste = classic.Posts.query.filter_by(user_id="1").all()
            posts = classic.Posts.query.all()
            return render_template('dashboard.html', posts=posts, poste=poste)
Related