我正在使用本指南创建一个多租户应用程序:https://medium.com/@smirnov.am/multitenancy-with-flask-6f5375a34f55
我遇到的问题是指南正在执行此行:
@simple_cache
def get_known_tenants():
tenants = Tenant.query.all()
return [i.name for i in tenants]
我在做类似的事情:
def get_known_organizations():
organizations = Organization.query.all()
return [o.organization_name_url for o in organizations]
我错过了什么,因为我得到的错误是:
AttributeError: 'NoneType' object has no attribute 'query'
模型
class Organization(db.Model):
organization_id = db.Column(db.Integer, primary_key=True)
cypher = db.Column(db.String(10), unique=True, nullable=False) # 10-character String representation to use as ID of the organization
organization_name = db.Column(db.String(100), unique=True, nullable=False) # Organization name as String (ex: Seattle Children's Hospital)
organization_name_url = db.Column(db.String(100), unique=True, nullable=False) # Parsed organization name to lowercase and with dashes to use as subdomain (ex: seattle-childrens-hospital)
website = db.Column(db.Text, unique=True, nullable=False) # URL of the organization's website
contact_phone = db.Column(db.String(15), unique=True, nullable=False) # Organization's contact number
ooo_phone = db.Column(db.String(15), unique=True, nullable=False) # Omedyari number
任何帮助,将不胜感激
我猜你在定义方法之前错过了@simple_cache。或者组织变量在任何实例上都更新为其他None值。
我发现了这个问题,好像当我去一个在postgres中没有特定数据库的网址时,它无法迭代它。