1

I'm having an issue deploying my first Django project.

Here's my config.yml:

global:
  application_name: testapp
  branch: null
  default_ec2_keyname: aws-eb
  default_platform: Python 3.8 running on 64bit Amazon Linux 2
  default_region: us-west-2
  include_git_submodules: true
  instance_profile: null
  platform_name: null
  platform_version: null
  profile: eb-cli
  repository: null
  sc: null
  workspace_type: Application

And here's my django.config:

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: djangoproject.wsgi:application

I have followed this doc. But after I did eb create testapp-env, I get 502 error: image of the error

I will provide further information if you need. Thank you in advance for your help.

Here's the error in web.stdout.log:

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.

UPDATE

My django project uses python-socketio, and here's my wsgi.py:

from django.core.wsgi import get_wsgi_application
import socketio
from post.socketioserver import sio # <- it's just my socket io code

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangoproject.settings')

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

I get another error:

django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

1 Answers1

0

You need to set the DJANGO_SETTINGS_MODULE environment variable:

option_settings:
   aws:elasticbeanstalk:container:python:
      WSGIPath: djangoproject.wsgi:application
   aws:elasticbeanstalk:application:environment:
      DJANGO_SETTINGS_MODULE: "djangoproject.settings"

Also you need to edit your wsgi.py file because you are accessing an app before Django setup:

import django
django.setup()

from django.core.wsgi import get_wsgi_application
import socketio
from post.socketioserver import sio # <- it's just my socket io code

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangoproject.settings')

django_app = get_wsgi_application()
application = socketio.WSGIApp(sio, django_app)
Alain Bianchini
  • 3,883
  • 1
  • 7
  • 27
  • @robust-person After you changed the `wsgi.py` file restart the server. After the restart you still see the same error in `web.stdout.log`? – Alain Bianchini Dec 04 '21 at 07:33
  • It seems like my wsgi.py and yours is pretty the same. Is there any flaws I made? – robust-person Dec 04 '21 at 07:34
  • @robust-person I have updated my answer (also restart the server) – Alain Bianchini Dec 04 '21 at 07:41
  • I'm still having the same issue. I'll update my question to include the error message. – robust-person Dec 04 '21 at 07:57
  • @robust-person This is a different error (we have resolved the first). Probably you are getting the new error because you write `from post.socketioserver import sio` before Django setup. I have updated my answer. If after you have restarted the server you still get the error, take a look at this [question](https://stackoverflow.com/questions/34114427/django-upgrading-to-1-9-error-appregistrynotready-apps-arent-loaded-yet). – Alain Bianchini Dec 04 '21 at 08:12