How solve"no python application found check your startup logs" error for Django + uWSGI + nginx stack
After several weeks i can find problem in my wsgi.py
. It common solution use os.environ['ENV']
for DJANGO_SETTINGS_MODULE
, but with deffrent users and permissions its dosen't work.
If you use in your wsgi.py
file something like this:
os.environ["DJANGO_SETTINGS_MODULE"] = "config.settings." + os.environ["ENV"]
And have problem with no python application found
- split your wsgi file. I can catch that os.environ["ENV"]
return empty string. I add it for my all user, use source and etc. But uwsgi in emperior mode don't see it.
You sould use wsgi_dev.py
and wsgi_production.py
where you can write somethink like this os.environ["DJANGO_SETTINGS_MODULE"] = "config.settings.production"
. It's not so elegant but solve this problems fine.
For use splitting wsgi you can write something like this in wsgi.py
import os
from django.core.wsgi import get_wsgi_application
if os.environ.get('DEV') is True:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.dev")
else:
os.environ.setdefault("DJANGO_SETTINGS_MODULE",
"config.settings.production")
application = get_wsgi_application()
Denis Savenko
Updated on August 01, 2020Comments
-
Denis Savenko over 3 years
I user Django 1.10 with uWSGI and nginx on ubuntu 16.04 and deploy my app with ansible. My project have not default structure, but quite common ( thank Two scoopce for this :). I use split dev and production settings and config folder instead 'name' project folder. It's looks like this:
|-- config | |-- __init__.py | |-- settings | | |-- __init__.py | | |-- base.py | | `-- dev.py | |-- urls.py | |-- wsgi_dev.py | `-- wsgi_production.py |-- manage.py `-- requirements.txt
My
production.py
genarate from ansible with security encrypt and locate in config/settings.With this config i get "no python application found check your startup logs". Uwsgi don't see my application.
( {{ }} it's jinja2 syntax for ansible )
/etc/uwsgi/sites/{{ project_name }}
[uwsgi] chdir = {{ django_root }} home = /home/{{ project_user }}/venvs/{{ project_name }} module = config.wsgi_production:application master = true processes = 5 socket = /run/uwsgi/{{ project_name }}.sock chown-socket = {{ project_user }}:www-data chmod-socket = 660 vacuum = true
-
ivbtar almost 6 yearsHi, how did you split wsgi files?
-
Roland about 3 yearsFor
searx
I found out that I had to run./manage.sh
with enabled virtual environment.# Searx virtual environment alias virtualenv="python3 /usr/lib/python3/dist-packages/virtualenv.py" export SEARX_PYENV="${HOME}/searx-ve" source "${SEARX_PYENV}/bin/activate"