bernardopires / django-tenant-schemas

Tenant support for Django using PostgreSQL schemas.
https://django-tenant-schemas.readthedocs.org/en/latest/
MIT License
1.46k stars 424 forks source link

The public urls configuration is never used #528

Open jbltx opened 6 years ago

jbltx commented 6 years ago

I'm currently testing your nice library, I have already made all the setup written in the doc and everything has worked as expected.

I added PUBLIC_SCHEMA_URLCONF to be able to separate routing between the main domain url and other tenants ones, and it seems to not work. My urls_public.py urlpatterns is an empty list, but when i go to http://localhost:8000 the Django debugger is showing me a 404 error with the message:

Using the URLconf defined in myapp.urls_tenants, Django tried these URL patterns, in this order:

admin/
graphql/
The empty path didn't match any of these.

Which is an error from the other urls configuration file.

Here is my settings:

ALLOWED_HOSTS = [
    '.localhost',
]
SHARED_APPS = [
    'tenant_schemas',
    'customers',
    'django.contrib.contenttypes',
    'django.contrib.auth',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.admin',
    'storages',
    'graphene_django',
]
TENANT_APPS = [
    'api',
]
INSTALLED_APPS = [
    'tenant_schemas',
    'customers',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.admin',
    'django.contrib.staticfiles',
    'storages',
    'graphene_django',
    'api',
]
MIDDLEWARE_CLASSES = [
    'tenant_schemas.middleware.TenantMiddleware',
]
ROOT_URLCONF = 'myapp.urls_tenants'
PUBLIC_SCHEMA_URLCONF = 'myapp.urls_public'
DATABASE_ROUTERS = (
    'tenant_schemas.routers.TenantSyncRouter',
)
TENANT_MODEL = 'customers.Client'
jbltx commented 6 years ago

Ok i found the issue, Django doesn't use MIDDLEWARE_CLASSES but MIDDLEWARE property in settings now. I just inserted 'tenant_schemas.middleware.TenantMiddleware' as first element of my MIDDLEWARE list and the good urls configuration file is used (should be nice to see a message in the documentation to warn us ;) ).

wanjohikibui commented 6 years ago

I'm still having difficulties with this. How did you setup the urls_public to ensure it worked? Thanks