我正在使用 django 尝试创建一个允许用户子域的网站。像 john.stackoverflow.com 这样的东西。我目前正在尝试设置 django 租户 schamas,即使我遵循文档,似乎也没有任何效果。我正在尝试使应用程序“主要”成为租户应用程序。因此,当用户转到 main 时,它会返回 user.website.com。尽管“django.core.exceptions.AppRegistryNotReady:应用程序尚未加载”,但我一直收到此错误。
这是我的设置文件:
INSTALLED_APPS = [
'tenant_schemas',
'main',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
TENANT_MODEL = "main.Client"
MIDDLEWARE = [
'tenant_schemas.middleware.TenantMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
SHARED_APPS = (
'tenant_schemas', # mandatory, should always be before any django app
'main', # you must list the app where your tenant model resides in
'django.contrib.contenttypes',
# everything below here is optional
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
)
TENANT_APPS = (
'django.contrib.contenttypes',
# your tenant-specific apps
'main',
)
DATABASES = {
'default': {
'ENGINE': 'tenant_schemas.postgresql_backend',
# ..
}
}
DATABASE_ROUTERS = (
'tenant_schemas.routers.TenantSyncRouter',
)