Unable to use manage.py due to uwsgi import in settings.py

I am using django 1.8 + uwsgi + nginx on my server. uwsgi is in imperial mode. I am importing the uwsgi python module in myapp / settings.py to enable autoloading on code changes. As I understood, this python module is only available for import when the python thread is started by a uwsgi employee. When I try to manually manage.py collectstatic imports settings.py and then fails to import uwsgi.py.

Is there a way to use the uwsgi python module while I can still use manage.py?

The code I'm using to enable autoloading (in myapp / sttings.py):

import uwsgi
from uwsgidecorators import timer
from django.utils import autoreload

    def change_code_gracefull_reload(sig):
    if autoreload.code_changed():



source to share

1 answer

You have to catch the exception ImportError

and get through.

except ImportError:


Alternatively, you can use a different settings file for your production server. This will import the settings from your regular file settings.py

and include imports and startup code.



All Articles