Django uwsgi import error

I have a Django project with one subscribe application. In root urls.py I use include from subscribe urls.py

I put subscribe in INSTALLED_APPS , and in subscribe urls.py I use subscribe.views.<name> to call my views. When the server works like python manage.py runserver locally, everything works fine. But when the server is running on nginx + uwsgi with virtualenv, I have ImportError: No module named subscribe . When I change subscribe to project.subscribe in INSTALLED_APPS and in subscribe urls.py change subscribe.views.<name> to project.subscribe.views.<name> , everything works fine.

uwsgi config:

 [uwsgi] socket = 127.0.0.1:9003 workers = 2 master = true virtualenv = /home/user/python chdir = /home/user env = DJANGO_SETTINGS_MODULE=project.settings module = django.core.handlers.wsgi:WSGIHandler() daemonize = /home/user/uwsgi.log 

Why should I use an absolute import path and how can I change it to relative back to nginx + uwsgi with virtualenv?

+7
source share
1 answer

The uwsgi configuration should include the pythonpath=/path/where/lives/settings.py/ directive, so the python interpreter will know where to find your applications.

Find more information about uwsgi configuration settings:

+7
source

All Articles