manage.py works but foreman start errors out
Question: This question is Heroku and django specific.

When I start my application using the command "python manage.py runserver",
the webserver starts without error. I can then go and retrieve the homepage my
visiting localhost:8000 in my browser. Great.

When I start my application using the command "foreman start", the webserver
also starts without error. it reads

    
    
    00:44:19 web.1  | started with pid 9736
    00:44:19 web.1  | 2014-09-22 00:44:19 [9736] [INFO] Starting gunicorn 19.0.0
    00:44:19 web.1  | 2014-09-22 00:44:19 [9736] [INFO] Listening at: http://0.0.0.0:5000 (9736)
    00:44:19 web.1  | 2014-09-22 00:44:19 [9736] [INFO] Using worker: sync
    00:44:19 web.1  | 2014-09-22 00:44:19 [9739] [INFO] Booting worker with pid: 9739
    

Awesome. When i try to visit localhost:5000, something goes awry. The page
reads "Internal server error." Huh. I look at the stacktrace that foreman
produces, and here is what I see:

    
    
    00:45:22 web.1  |     respiter = self.wsgi(environ, resp.start_response)
    00:45:22 web.1  |   File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
    00:45:22 web.1  |     self.load_middleware()
    00:45:22 web.1  |   File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/handlers/base.py", line 46, in load_middleware
    00:45:22 web.1  |     for middleware_path in settings.MIDDLEWARE_CLASSES:
    00:45:22 web.1  |   File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/conf/__init__.py", line 54, in __getattr__
    00:45:22 web.1  |     self._setup(name)
    00:45:22 web.1  |   File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/conf/__init__.py", line 49, in _setup
    00:45:22 web.1  |     self._wrapped = Settings(settings_module)
    00:45:22 web.1  |   File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/sitepackages/django/conf/__init__.py", line 132, in __init__
    00:45:22 web.1  |     % (self.SETTINGS_MODULE, e)
    00:45:22 web.1  | ImportError: Could not import settings 'gettingstarted.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named 'dj_database_url'
    

dj_database_url did not import correctly. Weird. "Import dj_database_url"
appears at the very top of my settings.py file.

If I activate my virtualenv and start python, I can run the command "import
dj_database_url". Furthermore, when i start the server using manage.py,
settings.py is opened, so the import must be working then as well. So why
would using foreman break this import?

Here is my wsgi.py:

    
    
    import os
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gettingstarted.settings")
    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()
    

Thank you in advance for any help


Answer: As `dj_database_url` is only installed in your virtual environment, make sure
when you run `foreman` the environment is activated; otherwise you'll see the
exception.

If you were to deploy this on Heroku, you would not have this problem because
by default Heroku will install from your `requirements.txt` file and thus your
environment will have `dj_database_url` and everything will work as expected.

I also see that you are using Python version 3.4 - unless you have a very
specific need, try to use Python 2.7x as some libraries are still being ported
to Python 3. You may run into unexplained errors later that are due to version
incompatibility.

