Python Forum

Full Version: TypeError: __repr__ returned non-string (type dict)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi I get this error : TypeError: __repr__ returned non-string (type dict)

class User(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(100))
    email = db.Column(db.String(100))
    password = db.Column(db.String(100))
    rank = db.Column(db.String(100), default='Newbie')
    def __repr__(self):
        #TypeError: __repr__ returned non-string (type dict)
        return {'name':self.username, 'rank': self.rank}

def dashboard():
    allusers = User.query.all()
    return render_template('dashboard.html', allusers=allusers)
I am trying to make the return statement look like a json but it doesnt works . Any help please?