2

I have a really weird situation I cannot seem to figure out. I have not touched my implementation of this package since the beginning of the year and now the functionality ceases to exist on my live heroku server. I currently have a Create Account form on my public tenant which generates a tenant/domain just as the docs do and django-tenants does its auto schema generation. This works correctly on my localhost and have zero problems. However on my live server, I proceed to get a 404 error... Not Found...The requested URL / was not found on this server.

I have a CNAME record on DNSimple which points to a wildcard domain that appears to be working, because I have already have a tenant I made awhile ago that is still completely functional (ie. some-customer.mydomain.com). I have looked into my PSQL db attached to heroku and everything is there as it should be, as well as the migrations occurring in the logs when I create an account which generates a tenant.

I was hoping that there might be some enlightenment as to what I am doing/have done wrong to make this issue occur. It just seems so odd that none of my now generated tenants can be accessed via their Domain.

Edit: Posting Code.

local .env file

SECRET_KEY=...
DEBUG=True
DB_NAME=...
DB_USER=...
DB_PASSWORD=...
DB_HOST=localhost
ALLOWED_HOSTS=.localhost, .herokuapp.com
GOOGLE_RECAPTCHA_SECRET_KEY=...
AWS_ACCESS_KEY_ID=...
AWS_SECRET_ACCESS_KEY=...
AWS_STORAGE_BUCKET_NAME=...
SECURE_SSL_REDIRECT='False'

settings.py (included things I think are relative)

...
LOGIN_URL = 'login'
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default=[], cast=Csv())
DEBUG = config('DEBUG', default=False, cast=bool)
SECRET_KEY = config('SECRET_KEY')
SHARED_APPS = (
    'django_tenants',
    'tenant',

    'django.contrib.contenttypes',

    'public.apps.PublicConfig',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.sessions',
    'debug_toolbar',
    'storages'
)

TENANT_APPS = (
    'django.contrib.contenttypes',

    'inventory.apps.InventoryConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.sessions',
    'django.contrib.messages',
)
INSTALLED_APPS = list(SHARED_APPS) + [app for app in TENANT_APPS if app not in SHARED_APPS]

TENANT_MODEL = 'tenant.Client'
TENANT_DOMAIN_MODEL = 'tenant.Domain'
MIDDLEWARE = [
    'django_tenants.middleware.main.TenantMainMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
]
ROOT_URLCONF = 'myapp.urls'
WSGI_APPLICATION = 'myapp.wsgi.application'
DATABASE_ROUTERS = (
    'django_tenants.routers.TenantSyncRouter',
)

PUBLIC_SCHEMA_URLCONF = 'myapp.urls_public'
SECURE_SSL_REDIRECT = config('SECURE_SSL_REDIRECT', default=False, cast=bool)
...

production Heroku settings (included relative stuff)

...
ALLOWED_HOSTS: .herokuapp.com, .mydomain.com, mydomain.com
DEBUG: False
SECURE_SSL_REDIRECT: True
...

urls.py (each tenant should see these)

urlpatterns = [
    ...
    url(r'^$', dashboard, name='dashboard'),
    url(r'^login/$', login_view, name='login'),
    url(r'^logout/$', logout_view, name='logout'),
    ...
]

urls_public.py (main site)

urlpatterns = [
    url(r'^$', home_view, name='home'),
    url(r'^login/$', login_view, name='login'),
    url(r'^logout/$', logout_view, name='logout'),
    url(r'^create_account/$', create_account_view, name='create_account'),
]
David Arce
  • 45
  • 1
  • 6
  • I assume on your dev environment you are doin something like `python manage.py runserver` and on your live system you are using wsgi and apache. If so the problem is proabably your apache config. Probably a missing redirect from http to https? – Red Cricket Sep 03 '18 at 01:52
  • I am using wsgi and gunicorn as far as I know. I can throw up my `.env` file and my `settings` if that would help. – David Arce Sep 03 '18 at 02:09
  • Maybe there is no '/' in your url patterns. Can you access your '/admin' url or any other urls like '/api/v1/whatever' on your live server? – Red Cricket Sep 03 '18 at 02:14
  • Yes I can access everything else, on my public tenant as well as my other tenant that I generated awhile ago. Links such as `sub-domain.mydomain.com/login/` and so forth. – David Arce Sep 03 '18 at 02:17
  • @RedCricket I posted some code. – David Arce Sep 03 '18 at 03:11
  • Hmm. Its normal for '/' to be 404 since there isn't any api url '/'. What do you expect to see? What shows up in your dev env? – Red Cricket Sep 03 '18 at 04:19
  • @RedCricket In my **production** environment, on the tenant that is working (no difference between other tenants as far as I know), when I try to access "/", I am redirected to the login page which is defined in my settings. However, with any other tenant I get 404. In my **dev** environment, every tenant redirects to the login page which is what I expect. – David Arce Sep 03 '18 at 04:28
  • I don't know anything about Heroku. But it sounds like Django and gunicorn and your DNS are ok. You should probably look at how Heroku is configure and the differences between your dev and prod envs. – Red Cricket Sep 03 '18 at 04:37
  • I have, I am just not sure where to go for help on Heroku... – David Arce Sep 03 '18 at 04:41

1 Answers1

0

Everything seems to look fine. If you try generating a tenant using the django-tenant docs in the shell on your production server by doing heroku run python manage.py shell -a yourapp and that works, then there is something wrong with your code that generates the tenants which you have not posted.

Oh Great One
  • 374
  • 2
  • 17