Django 1.5 + gunicorn - No module named website.wsgi?

Question

I am taking over this django legacy project which was built on **1.5.12**. I have no idea why they decided to remove wsgi.py from the project. So I am trying to put it back it. 

wsgi.py

    import os
    
    # We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
    # if running multiple sites in the same mod_wsgi process. To fix this, use
    # mod_wsgi daemon mode with each site in its own daemon process, or use
    # os.environ["DJANGO_SETTINGS_MODULE"] = "website.settings"
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "website.settings")
    
    # This application object is used by any WSGI server configured to use this
    # file. This includes Django's development server, if the WSGI_APPLICATION
    # setting points here.
    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()


settings.py:

    try:
        from local_settings import *
    except ImportError:
        from default_settings import *

default_settings.py:

    ...
    ...
    ROOT_URLCONF = 'website.urls'
    
    # Python dotted path to the WSGI application used by Django's runserver.
    WSGI_APPLICATION = 'website.wsgi.application'

Then I compile the project with:

    $ python manage.py runserver 0.0.0.0:8000

    Validating models...
    
    0 errors found
    May 20, 2017 - 07:47:34
    Django version 1.5.12, using settings 'website.settings'
    Development server is running at http://0.0.0.0:8000/
    Quit the server with CONTROL-C.

It works fine and I can see `wsgi.pyc` is generated.

But when I run it with `gunicorn`, I get this error:

    No module named website.wsgi

Details output:

    $ gunicorn website.wsgi:application                 
    2017-05-20 07:50:00 [4552] [INFO] Starting gunicorn 18.0
    2017-05-20 07:50:00 [4552] [INFO] Listening at: http://127.0.0.1:8000 (4552)
    2017-05-20 07:50:00 [4552] [INFO] Using worker: sync
    2017-05-20 07:50:00 [4556] [INFO] Booting worker with pid: 4556
    2017-05-20 07:50:00 [4556] [ERROR] Exception in worker process:
    Traceback (most recent call last):
      File "/var/www/html/foo/.env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
        worker.init_process()
      File "/var/www/html/foo/.env/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
        self.wsgi = self.app.wsgi()
      File "/var/www/html/foo/.env/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
        self.callable = self.load()
      File "/var/www/html/foo/.env/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
        return self.load_wsgiapp()
      File "/var/www/html/foo/.env/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
        return util.import_app(self.app_uri)
      File "/var/www/html/foo/.env/local/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
        __import__(module)
    ImportError: No module named website.wsgi
    Traceback (most recent call last):
      File "/var/www/html/foo/.env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
        worker.init_process()
      File "/var/www/html/foo/.env/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
        self.wsgi = self.app.wsgi()
      File "/var/www/html/foo/.env/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
        self.callable = self.load()
      File "/var/www/html/foo/.env/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
        return self.load_wsgiapp()
      File "/var/www/html/foo/.env/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
        return util.import_app(self.app_uri)
      File "/var/www/html/foo/.env/local/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
        __import__(module)
    ImportError: No module named website.wsgi
    2017-05-20 07:50:00 [4556] [INFO] Worker exiting (pid: 4556)
    2017-05-20 07:50:00 [4552] [INFO] Shutting down: Master
    2017-05-20 07:50:00 [4552] [INFO] Reason: Worker failed to boot.

Why? What have I missed?

Guest May 20, 2017, 8:10 a.m. 0 Answer

Warning! You are not logged in.
Your answer will be published as Guest user.

Post your Answer

 Prev question