Syntax error defining def _ _ repr__ (self): in python2.7 class class

I just started to learn python2.7, compared to the examples in the book, but when I write here, I always report grammatical errors.
looked at it, and searched the Internet, but didn"t find out where the mistake was.

this is the source code:

class User(db.Model):
    __tablename__ = "users"
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), unique=True, index=True)
    role_id = db.Column(db.Integer, db.ForeignKey("roles.id")

    def __repr__(self):
        return "<User %r>" % self.username

this is the compilation error:

  File "hello.py", line 44
    def __repr__(self):
      ^
SyntaxError: invalid syntax

Mar.03,2021

role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))

lack of parentheses


User:%r less colons

Menu