django project getting error on gunicorn but running perfectly on using manage.py runserver

Viewed 162

My django project is working perfectly on using manage.py runserver.

But when I am running it using gunicorn mysite.wsgi then it is giving errors

my wsgi.py

import os
from django.core.wsgi import get_wsgi_application
import socketio
from myapp.websocketserver import sio
import eventlet

os.environ["DJANGO_SETTINGS_MODULE"]="mysite.settings"

django_app = get_wsgi_application()
application = socketio.WSGIApp(sio, django_app)

eventlet.wsgi.server(eventlet.listen(('', 8000)), application)

Now these are some errors I am getting with gunicorn

on running=> gunicorn mysite.wsgi

django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS,
but settings are not configured. You must either define the environment variable 
DJANGO_SETTINGS_MODULE
or call settings.configure() before accessing settings.

then I run=> gunicorn --env DJANGO_SETTINGS_MODULE=mysite.settings backend.wsgi

raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

then I added this code in settings.py

import django
django.setup()

now I ran=> gunicorn --env DJANGO_SETTINGS_MODULE=mysite.settings backend.wsgi then I am getting this error:

raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

My settings.py has SECRET_KEY variable. And I am not getting any solution for this.

When my project is working fine with runserver then what is problem with gunicron. How to resolve these error

0 Answers
Related