Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How solve"no python application found check your startup logs" error for Django + uWSGI + nginx stack

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
like image 379
Denis Savenko Avatar asked Feb 12 '17 08:02

Denis Savenko


People also ask

Can I use uWSGI without nginx?

Can I then ditch NGINX? uWSGI could be used as a standalone web server in production, but that is not it's intentional use. It may sound odd, but uWSGI was always supposed to be a go-between a full-featured web server like NGINX and your Python files.

What is uWSGI in nginx?

Nginx implements a uwsgi proxying mechanism, which is a fast binary protocol that uWSGI can use to talk with other servers. The uwsgi protocol is actually uWSGI's default protocol, so simply by omitting a protocol specification, it will fall back to uwsgi .

What does uWSGI?

uWSGI is an open source software application that "aims at developing a full stack for building hosting services". It is named after the Web Server Gateway Interface (WSGI), which was the first plugin supported by the project. uWSGI is maintained by Italian based software company unbit.


1 Answers

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()
like image 177
Denis Savenko Avatar answered Oct 19 '22 20:10

Denis Savenko