flask.has_request_context()[source]

If you have code that wants to test if a request context is there or not this function can be used. For instance, you may want to take advantage of request information if the request object is available, but fail silently if it is unavailable.

class User(db.Model):

if remote_addr is None and has_request_context():


Alternatively you can also just test any of the context bound objects (such as request or g for truthness):

class User(db.Model):