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


Messages In This Thread
TypeError: __repr__ returned non-string (type dict) - by shockwave - May-17-2020, 05:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting "name 'get_weather' is not defined error and no json_data returned? trthskr4 6 455 Sep-14-2021, 09:55 AM
Last Post: trthskr4
  Libraries installed with pipenv, but ModuleNotFoundError returned jpncsu 2 351 Sep-06-2021, 07:24 PM
Last Post: jpncsu
  You have any idea, how fix TypeError: unhashable type: 'list' lsepolis123 2 811 Jun-02-2021, 07:55 AM
Last Post: supuflounder
  TypeError: int() argument must be a string, a bytes-like object or a number, not 'Non Anldra12 2 1,493 May-02-2021, 03:45 PM
Last Post: Anldra12
  TypeError: __str__ returned non-string (type tuple) Anldra12 1 1,795 Apr-13-2021, 07:50 AM
Last Post: Anldra12
  What type of *data* is the name of a list/tuple/dict, etc? alloydog 9 1,246 Jan-30-2021, 07:11 AM
Last Post: alloydog
Question dict value, how to change type from int to list? swissjoker 3 918 Dec-09-2020, 09:50 AM
Last Post: perfringo
  TypeError: string indices must be integers hendern 2 1,106 Oct-02-2020, 10:16 PM
Last Post: hendern
  TypeError: 'type' object is not subscriptable Stef 1 1,633 Aug-28-2020, 03:01 PM
Last Post: Gribouillis
  String index out of bounds ( Python : Dict ) kommu 2 907 Jun-25-2020, 08:52 PM
Last Post: menator01

Forum Jump:

User Panel Messages

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