Reputation: 41
I am new to Python Django. I am working on a Django project using Ubuntu, nginx and python, Django.
Question is that : I am able to open the application with URL name in browser like: http://example.com . But the application is NOT opening locally in server with localhost:8000 or public-ip:8000, below is the output of related commands:
$ wget -O- http://localhost:8000
--2017-01-17 13:15:30-- localhost:8000
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:8000... connected.
HTTP request sent, awaiting response... 404 NOT FOUND
2017-01-17 13:15:30 ERROR 404: NOT FOUND.
$ netstat -lan | grep 8000
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN
$ elinks http:// localhost:8000
Page not found at /
Page not found (404)
Request Method: GET
Request URL: http:// localhost:8000/
Raised by: mainpages.views.index
No tenant for hostname "localhost"
You're seeing this error because¤you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
Please help.
Upvotes: 1
Views: 4051
Reputation: 433
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
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.
Upvotes: 1
Reputation: 1463
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
Upvotes: 1
Reputation: 43320
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.
Upvotes: 0