[Answered ]-Not able to open http://localhost:8000/ but opening in public ip ngnix Django

1👍

this is because you are using tenant_schema in your application. and you are running your application without creating a tenant. so the django is saying you to create a tenant first.

That is:
after making use of

python manage.pt makemigrations and migrate

command
post data into your tenant model table that you have created using

python manage.py shell

python shell will prompt. here import your tenant model class. and pass data into it.
ex

python manage.py shell
>>> from xyz_app.models import Client
>>>
>>> Client(domain_url='energy.mystupidurl.com', schema_name='public', name='public', paid_until = '2099-12-31', on_trial =False).save()

here Client is tenant here. and

domain_url, schema_name, pain_untill, and on_trial

are variable of the class

Client

1👍

This is the steps I followed after configure shared and tenant apps:

SHARED_APPS = [
    'tenant_schemas',  # mandatory
    'empresas',  # you must list the app where your tenant model resides in

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.contenttypes',
    'import_export',
    'bootstrap4',
    'usuarios',

]

TENANT_APPS = [
    'app',
    'productos',
    'ventas',
    'medidas',
    # 'app.apps.AppConfig',
    # 'usuarios.apps.UsuariosConfig',
    # 'productos.apps.ProductosConfig',
    # 'ventas.apps.VentasConfig',
    # 'medidas.apps.MedidasConfig',
]

INSTALLED_APPS = list(SHARED_APPS) + [app for app in TENANT_APPS if app not in SHARED_APPS]

TENANT_MODEL = "empresas.Empresa" # app.Model
TENANT_DOMAIN_MODEL = "empresas.Domain" # app.Model

SITE_ID = 1
  • Delete mi postgres schemas
  • Create public schema
  • Delete all migrations in all apps
  • Create a file with the admin/public and 2 tenants at empresas app. Just to place the code backup:
    from empresas.models import Empresa
    tenant = Empresa(domain_url = 'kinetfood.local',
                    schema_name = 'public',
                    nombre = 'Kirios Net',
                    nro_mesas = '4',
                    )
    tenant.save()

    tenant = Empresa(domain_url = 'titu.kinetfood.local',
                    schema_name = 'titu',
                    nombre = 'Titu Cocktail Xpress',
                    nro_mesas = '4',
                    )
    tenant.save()

    tenant = Empresa(domain_url = 'lasalva.kinetfood.local',
                    schema_name = 'lasalva',
                    nombre = 'La Salva burguer',
                    nro_mesas = '10',
                    )
    tenant.save()
  • Duplicate the file kinetfood/urls.py and rename the copy to: public_urls.py

  • Add to settings PUBLIC_SCHEMA_URL_CONF = 'kinetfoood.public_urls'

  • Run python manage.py makemigrations

  • Run python manage.py migrate_schemas --shared

  • Run python .\manage.py shell and paste the create_tenant script, double Enter.

  • Set the same host dirs at: C:\Windows\System32\drivers\etc on Windows

    # localhost name resolution is handled within DNS itself.
    #   127.0.0.1       localhost
    #   ::1             localhost
    127.0.0.1       localhost
    255.255.255.255 broadcasthost
    ::1             localhost

    127.0.0.1       kinetfood.local
    127.0.0.1       titu.kinetfood.local
    127.0.0.1       lasalva.kinetfood.local
  • Run python .\manage.py runserver

  • Put the url domain in browser http://titu.kinetfood.local:8000/

  • Voilá

I hope this helps you.

0👍

According to the docs for django-tennant-schemas (which I presume you’re using) it states:

If the hostname in the request does not match a valid tenant domain_url, a HTTP 404 Not Found will be returned. )

So simply make a tenant that you can use for your localhost.

👤Sayse

Leave a comment