Solve the problem of “typeerror: ‘bool’ object is not callable” in flash and Django

> Welcome to Flask’s large tutorial project! When it comes time to refactor the user model, run the script and it says :

TypeError: ‘bool’ object is not callable

This is the user model:

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True) nickname = db.Column(db.String(64), index=True, unique=True) email = db.Column(db.String(120), index=True, unique=True) posts = db.relationship('Post', backref='author', lazy='dynamic')  @property def is_authenticated(self): return True  @property def is_active(self): return True  @property def is_anonymous(self): return False def get_id(self): try: return unicode(self.id) # python 2 except NameError: return str(self.id) # python 3 def __repr__(self): return '<User %r>' % (self.nickname) 

This is the code at the time of the call:

from flask import render_template, flash, redirect, session, url_for, request, g
from flask.ext.login import login_user, logout_user, current_user, login_required
from app import app, db, lm, oid from .forms import LoginForm from .models import User @app.route('/login', methods=['GET', 'POST']) @oid.loginhandler def login(): if g.user is not None and g.user.is_authenticated(): # error return redirect(url_for('index')) form = LoginForm() if form.validate_on_submit(): session['remember_me'] = form.remember_me.data return oid.try_login(form.openid.data, ask_for=['nickname', 'email']) return render_template('login.html', title='Sign In', form=form, providers=app.config['OPENID_PROVIDERS']) 

is_authenticated is a property, not a method, as described in Resources, so just remove the parentheses. There are two typos in this section of the book. Please refer to the Git source code.

put the wrong place:
if g.user is not None and g.user.is_authenticated():
if g.user is not None and G.user. is_authenticated:
and then no error.

Similar Posts: