Python Forum
AttributeError: 'dict' object has no attribute 'is_active' (PyMongo And Flask)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError: 'dict' object has no attribute 'is_active' (PyMongo And Flask)
#1
@app.route("/register", methods=['GET', 'POST'])
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        users = mongo.db.users
        hash_password=bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        eml=form.email.data
        gen=form.gender.data
        ctry=form.country.data
        profile={'name' : form.username.data, 'password' :hash_password,'email':eml,'gender':gen,'country':ctry}
        users.insert(profile)
        #users.insert({'name' : form.username.data, 'password' :form.password.data})
        flash(f'Your has been Account created for Username {form.username.data}!, You can login', 'success')
        return redirect(url_for('login'))
        #return redirect(url_for('home'))
    return render_template('register.html', title='Register', form=form)

@app.route("/login", methods=['GET', 'POST'])
def login():
    form = LoginForm()
    if form.validate_on_submit():
        users = mongo.db.users
        loginuser = users.find_one({'email' : form.email.data})
        if loginuser and bcrypt.check_password_hash(loginuser['password'],form.password.data):
        #if form.email.data == '[email protected]' and form.password.data == 'password':
            login_user(loginuser,remember=form.data.remember)
            return redirect(url_for('home'))
            #flash('You have been logged in!', 'success')
            #return redirect(url_for('home'))
        else:
            flash('Login Unsuccessful. Please check username and password', 'danger')
    return render_template('login.html', title='Login', form=form)
I have created a simple register and login method using flask with combination of pymongo. Now for user session management i am using flask_login but it gives me this error AttributeError: 'dict' object has no attribute 'is_active'

the solution that i found different post was to add UserMaxIn in UserClass but i dont have any class for User Model and i dont want to make it either

what would be the solution of this error ?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to fix "'dict_values' object has no attribute 'inject_wsgi'" in session_transacti devid 0 1,138 Aug-13-2023, 07:52 AM
Last Post: devid
  AttributeError: 'ellipsis' object has no attribute 'register_blueprint' Mechanicalpixelz 2 2,358 Dec-29-2021, 01:30 AM
Last Post: Mechanicalpixelz
  Flask TypeError: Object of type Decimal is not JSON serializable mekacharan 0 3,890 Jul-15-2021, 05:28 AM
Last Post: mekacharan
  AttributeError: 'NoneType' object in a parser - stops it apollo 4 3,966 May-28-2021, 02:13 PM
Last Post: Daring_T
  AttributeError: ResultSet object has no attribute 'get_text' KatMac 1 4,338 May-07-2021, 05:32 PM
Last Post: snippsat
  Python 3.9 : BeautifulSoup: 'NoneType' object has no attribute 'text' fudgemasterultra 1 8,816 Mar-03-2021, 09:40 AM
Last Post: Larz60+
  'NavigableString' object has no attribute 'h2' RandomCoder 5 5,312 May-20-2020, 09:01 AM
Last Post: Larz60+
  AttributeError: 'str' object has no attribute 'xpath' nazmulfinance 4 10,389 Nov-11-2019, 05:15 PM
Last Post: nazmulfinance
  AttributeError: 'str' object has no attribute 'xpath' nazmulfinance 0 3,022 Nov-10-2019, 09:13 PM
Last Post: nazmulfinance
  form.populate_obj problem "object has no attribute translate" pascale 0 3,622 Jun-12-2019, 07:30 PM
Last Post: pascale

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020