I am quite new to python and am working on my first django project. I followed this tutorial. I managed to configure all the things but django app itself. It works if I run django server alone, however it does not work when started by uwsgi.
This is my uwsgi conf:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "api.settings")
application = get_wsgi_application()
And error from uwsgi log:
--- no python application found, check your startup logs for errors ---
So I looked up for startup errors:
Traceback (most recent call last):
  File "./wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "/var/www/api.partycon.net/virtualpy/local/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    django.setup()
  File "/var/www/api.partycon.net/virtualpy/local/lib/python2.7/site-packages/django/__init__.py", line 17, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "/var/www/api.partycon.net/virtualpy/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
    self._setup(name)
  File "/var/www/api.partycon.net/virtualpy/local/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup
    self._wrapped = Settings(settings_module)
  File "/var/www/api.partycon.net/virtualpy/local/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named api.settings
My project's dirtree:
.
|-- api
|   |-- __init__.py
|   |-- __init__.pyc
|   |-- media
|   |   `-- sample-media.jpg
|   |-- settings.py
|   |-- settings.pyc
|   |-- urls.py
|   |-- urls.pyc
|   |-- wsgi.py
|   `-- wsgi.pyc
|-- db.sqlite3
|-- manage.py
|-- static
|   `-- admin
|       ... ... ... ...
|-- uwsgi_conf.ini
`-- uwsgi_params
I hope I provided enough information, however I can tell u more - the problem is that I actually have no idea where to look.
Thanks in advance :)
That's the simple answer, anyway -- you don't need it. uWSGI is itself a capable server.
You are probably lacking a chdir line in your uwsgi_conf.ini. Or, probably, you have a chdir line, but it is wrong.
This is confirmed by your traceback:
File "./wsgi.py", line 16, in <module>
Here you should see ./api/wsgi.py, not ./wsgi.py.
Clearly, the working directory of uWSGI is the api/ directory, while it should be the parent directory.
In general, your uWSGI configuration file should look like this:
[uwsgi] chdir=/path/to/your/project module=mysite.wsgi:application ...
See also the Django documentation on uWSGI.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With