i've got a challenge with run django project on production server with Apache and mod_wsgi. This Error happened when i am start apache and visit site very first time or move from other:
ImportError at /
Exception Value: cannot import title MyName
Exception Location /var/www/projectname/appname/somemodule.py
When i am reload page the mistake vanishes and work fine. Another point is this fact error happened selectively and sometime not appear.
In project i am use imports without project title prefix (i am talking about 'from accounts.models import Account' rather 'from projectname.accounts.models import Account').
On development (manage.py runserver) server all work fine with no troubles.
I have tried personally many versions of my apache and wsgi script designs but issue is not solved.
Here my current projectname.wsgi:
#!/usr/bin/env python import os, sys, re sys.path.append('/var/www/projectname') sys.path.append('/var/www') os.environ['PYTHON_EGG_CACHE'] = '/var/www/projectname/.python-egg' os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()
Here's certain parts from apache config:
<VirtualHost ip:80> ServerAdmin email@example.com DocumentRoot /var/www ServerName www.projectname.com WSGIScriptAlias / "/var/www/projectname/projectname.wsgi" WSGIDaemonProcess projectname threads=5 maximum-requests=5000 <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ....
Also i am make use of a separate Virtual Host for SSL.
I really hope somebody assist me to.
I give a similar problem and also the cause could be that the 'current directory' was 'www' and never root project dir.
Within the django development server the server atmosphere is placed based on the current project you're working. For this reason the import errors occur while shifting to Apache.
While using the import use " from projectname.appname.models import MyModel ". Be as specefic as possible.
Use sys.path.append('location/to/your_project_foler/') inside your situation "/var/www"
Only a suggestion:
Likewise try to create-up django in another url than root. I additionally were built with a similar problem while attempting to run django on the website root, i.e. : WSGIScriptAlias /< some url > "/var/www/projectname/projectname.wsgi"