[Fixed]-How I fix erro in gunicorn when I deploy django app in Heroku?

1👍

It looks like you are missing some modules that gunicorn is trying to import. This usually happens because you haven’t installed all necessary requirements. Typically, if you already have a requirements.txt file, you can use the following command to install your project’s requirements:

pip install -r requirements.txt

This becomes slightly more complicated if you re using a virtual environment where you will have to make sure that gunicorn is using the virtual env that you have set up.


I just noted some updates to the original post. As an FYI—the except clause here will never be reached:

if bool(var):
    try:
        os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings.server_settings")
    except ImportError:
        os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings.locals_settings")

setdefault will just set the environment variable, it won’t ever trigger any imports until it is used.

👤2ps

Leave a comment