I have a Django app which runs fine on localhost. But when I try it on the server, it gives me the following error (as seen in DEBUG output):
No module named views
Request Method: GET
Request URL: url_to_site/accounts/login
Django Version: 1.6.1
Exception Type: ImportError
Exception Value:
No module named views
Exception Location: /opt/dev/site/smsmessages/views.py in <module>, line 1
Python Executable: /usr/bin/python
Python Version: 2.6.6
Python Path:
['/opt/dev/myfolder/project/app',
'/opt/dev/myfolder/project',
'/usr/lib64/python26.zip',
'/usr/lib64/python2.6',
'/usr/lib64/python2.6/plat-linux2',
'/usr/lib64/python2.6/lib-tk',
'/usr/lib64/python2.6/lib-old',
'/usr/lib64/python2.6/lib-dynload',
'/usr/lib64/python2.6/site-packages',
'/usr/lib64/python2.6/site-packages/gtk-2.0',
'/usr/lib/python2.6/site-packages']
Part of he stack trace is as follow:
/opt/dev/myfolder/project/app/urls.py in <module>
url(r'^messages/', include('smsmessages.urls', namespace='smsmessages', app_name='smsmessages')),
[some more stack trace output here...]
/opt/dev/myfolder/project/smsmessages/urls.py in <module>
from smsmessages.views import MessageCreateView, MessageListView, MessageUpdateView, MessageDeleteView
[...]
/opt/dev/myfolder/project/smsmessages/views.py in <module>
from braces.views import LoginRequiredMixin
I use Django-braces in this app. But it baffles me that the app works without any glitch when I run:
$ python manage.py runserver
on the same server and:
$ curl mysite
<site's content is returned here without a glitch>
Importing braces.views
also seems to work when I do:
$ python manage.py shell
(InteractiveConsole)
>>> from braces.views import *
>>> print "no problem here"
It is only when I go back to Apache as server, then I face the aforementioned error (even with curl
).
This makes me wonder if it's either wsgi.py or/and Apache ('2.2.15 (Red Hat)') config that is/are causing the problem. Part of the meta info returned by DEBUG message regarding wsgi and Apache is as follow.
mod_wsgi.listener_port '80'
mod_wsgi.listener_host ''
SERVER_SOFTWARE 'Apache/2.2.15 (Red Hat)'
SCRIPT_NAME u''
mod_ssl.var_lookup ''
mod_wsgi.handler_script ''
SERVER_SIGNATURE '<address>Apache/2.2.15 (Red Hat) Server at site.com Port 80</address>\n'
REQUEST_METHOD 'GET'
PATH_INFO u'/accounts/login'
SERVER_PROTOCOL 'HTTP/1.1'
mod_wsgi.request_handler 'wsgi-script'
wsgi.url_scheme 'http'
PATH_TRANSLATED '/opt/dev/myfolder/project/app/wsgi.py/accounts/login'
wsgi.multiprocess True
mod_wsgi.input_chunked '0'
DOCUMENT_ROOT '/var/www/html'
mod_wsgi.process_group ''
SCRIPT_FILENAME '/opt/dev/myfolder/project/app/wsgi.py'
The content of wsgi.py
is:
import os, sys
sys.path.append('/usr/lib64/python2.6/site-packages/')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Apache configs are as follows:
WSGIPythonPath /opt/dev/myfolder/project/
<Directory /opt/dev/myfolder/project/app>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
<VirtualHost *:80>
Alias /static/ /opt/dev/myfolder/app/static/
ServerAdmin email@email.com
ServerName site.com
ErrorLog logs/site.com-error_log
CustomLog logs/site.com-access_log common
WSGIScriptAlias / /opt/dev/myfolder/project/app/wsgi.py
Is there anything that I am doing wrong or missing? Has anyone seen this error? I've explored everything I could (including the ones on StackOverflow regarding No module named views
, but I would really appreciate if somebody who's experienced in Django, Apache, wsgi and probably Django-braces could tell me what might be wrong here. Thank you very much.