Python Forum
TypeError: __repr__ returned non-string (type dict)
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: __repr__ returned non-string (type dict)
#1
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: string indices must be integers deneme2 2 599 Feb-14-2025, 12:23 AM
Last Post: deneme2
Question TypeError: argument of type 'NoneType' is not iterable Tajaldeen 7 2,088 Nov-29-2024, 09:45 AM
Last Post: Tajaldeen
  TypeError: string indices must be integers, not 'str' LEMA 2 2,249 Jun-12-2024, 09:32 PM
Last Post: LEMA
  question about __repr__ in a class akbarza 4 1,644 Jan-12-2024, 11:22 AM
Last Post: DeaD_EyE
  How to access values returned from inquirer cspower 6 2,547 Dec-26-2023, 09:34 PM
Last Post: cspower
  boto3 - Error - TypeError: string indices must be integers kpatil 7 3,037 Jun-09-2023, 06:56 PM
Last Post: kpatil
  "TypeError: string indices must be integers, not 'str'" while not using any indices bul1t 2 5,583 Feb-11-2023, 07:03 PM
Last Post: deanhystad
  reading a table which is of type string saisankalpj 2 1,858 Dec-03-2022, 11:19 AM
Last Post: saisankalpj
  TypeError: string indices must be integers JonWayn 12 5,710 Aug-31-2022, 03:29 PM
Last Post: deanhystad
  TypeError: unsupported operand type(s) for +: 'dict' and 'int' nick12341234 1 11,220 Jul-15-2022, 04:04 AM
Last Post: ndc85430

Forum Jump:

User Panel Messages

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