TypeError: __repr__ returned non-string (type dict) - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: TypeError: __repr__ returned non-string (type dict) (/thread-26893.html) |
TypeError: __repr__ returned non-string (type dict) - shockwave - May-17-2020 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} @app.route('/dashboard') @login_required def dashboard(): allusers = User.query.all() print(allusers.__repr__()) 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? |