7

I'm going through the "example" project into production on a VPS CentOS 6 (with Plesk) with python2.7, mod_wsgi, Django 1.6 I have proven many configurations and I always get error "No module named settings" or "No module named Unipath". Not that I have wrong or I'm missing. Thanks and regards.

My vhost.conf:

Alias /static/ /var/www/vhosts/example.com/httpdocs/
Alias /media/ /var/www/vhosts/example.com/httpdocs/media/

WSGIScriptAlias / /var/www/vhosts/example.com/example.wsgi

<Directory /var/www/vhosts/example.com>
    Order allow,deny
    Allow from all
</Directory>

My example.wsgi:

import os
import sys

path = '/var/www/vhosts/example.com/example'
if path not in sys.path:
   sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

I put my project via ftp into : /var/www/vhosts/example.com/

example.com/
      example(project)
          settings.py
          urls.py
          ...
      app
          models.py
          forms.py
          views.py
          ...
      templates
      httpdocs
      example.wsgi
      manage.py

Thanks again...

user3356409
  • 73
  • 1
  • 1
  • 5

3 Answers3

2

Your settings are in example app so it should be:

os.environ['DJANGO_SETTINGS_MODULE'] = 'example.settings'
0

Go read the official Django documentation on how to setup things for mod_wsgi:

You are not setting the Python module search path or DJANGO_SETTINGS_MODULE as described in that document.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
0

Use WSGIDaemonProcess & WSGIProcessGroup

You can solve this issue by setting the python-path in apache2 config to point at your django project directory

Alias /static/ /var/www/vhosts/example.com/httpdocs/
Alias /media/ /var/www/vhosts/example.com/httpdocs/media/

WSGIScriptAlias / /var/www/vhosts/example.com/example.wsgi

WSGIDaemonProcess example.com processes=2 threads=15 display-name=%{GROUP} python-path=/var/www/vhosts
WSGIProcessGroup example.com

<Directory /var/www/vhosts/example.com>
    Order allow,deny
    Allow from all
</Directory>
Community
  • 1
  • 1
Jossef Harush Kadouri
  • 32,361
  • 10
  • 130
  • 129
  • 1
    Except that you should not be using embedded mode. Use daemon mode of mod_wsgi and it is the ``python-path`` option to ``WSGIDaemonProcess``. Repeat, you should never be using embedded mode unless you are stuck with Windows. – Graham Dumpleton Aug 16 '15 at 21:54
  • @GrahamDumpleton, thanks for the comment, i also read [your blog post](http://blog.dscpl.com.au/2012/10/why-are-you-using-embedded-mode-of.html). i wasn't aware of daemon mode. thank you! edited my answer – Jossef Harush Kadouri Aug 17 '15 at 05:14