Django site runs with dev server but not on Apache mod_wsgi
I have some Django websites and I want to place them on the webserver Apache2 with mod_wsgi.
The webserver works and one Django website works correctly, but the other one doesn't (it shows the Internal Server Error page). But the strange thing is that the website works perfect on the develop server.
This is my vhost config:
<VirtualHost *:8080>
DocumentRoot "C:\wamp\www\mySite"
ServerName mysite.dev.businessx.local
ErrorLog C:\wamp\www\mySite\log\error_log
CustomLog C:\wamp\www\mySite\log\access_log common
<Directory "C:\wamp\www\mySite">
Options Indexes FollowSymLinks Includes
AllowOverride All
Order allow,deny
Allow from All
</Directory>
WSGIScriptAlias / "c:/wamp/www/mySite/django2.wsgi"
</VirtualHost>
And this is the django2.wsgi:
import os, sys
sys.path.append('c:/wamp/www/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mySite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
And under is the error that ends up in the error log of apache when I try to acces the website. It states that it can't import the module mySite.main and main is a subfolder/app of the project.
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] TemplateSyntaxError: Caught ImportError while rendering: No module named ClickF1.main
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] mod_wsgi (pid=4976): Exception occurred processing WSGI script 'C:/wamp/www/clickf1/django2.wsgi'.
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] Traceback (most recent call last):
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\core\\handlers\\wsgi.py", line 248, in __call__
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] response = self.get_response(request)
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\core\\handlers\\base.py", line 141, in get_response
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] return self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\core\\handlers\\base.py", line 165, in handle_uncaught_exception
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] return debug.technical_500_response(request, *exc_info)
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\views\\debug.py", line 59, in technical_500_response
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] html = reporter.get_traceback_html()
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\views\\debug.py", line 141, in get_traceback_html
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] return t.render(c)
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\template\\__init__.py", line 173, in render
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] return self._render(context)
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\template\\__init__.py", line 167, in _render
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] return self.nodelist.render(context)
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\template\\__init__.py", line 796, in render
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] bits.append(self.render_node(node, context))
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\template\\debug.py", line 72, in render_node
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] result = node.render(context)
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\template\\debug.py", line 89, in render
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] output = self.filter_expression.resolve(context)
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\template\\__init__.py", line 579, in resolve
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] new_obj = func(obj, *arg_vals)
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\template\\defaultfilters.py", line 682, in date
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] return format(value, arg)
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\utils\\dateformat.py", line 281, in format
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] return df.format(format_string)
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] Fil开发者_开发问答e "C:\\Python27\\lib\\site-packages\\django\\utils\\dateformat.py", line 30, in format
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] pieces.append(force_unicode(getattr(self, piece)()))
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\utils\\dateformat.py", line 187, in r
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] return self.format('D, j M Y H:i:s O')
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\utils\\dateformat.py", line 30, in format
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] pieces.append(force_unicode(getattr(self, piece)()))
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\utils\\encoding.py", line 66, in force_unicode
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] s = unicode(s)
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\utils\\functional.py", line 206, in __unicode_cast
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] return self.__func(*self.__args, **self.__kw)
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\utils\\translation\\__init__.py", line 55, in ugettext
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] return real_ugettext(message)
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\utils\\functional.py", line 55, in _curried
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\utils\\translation\\__init__.py", line 36, in delayed_loader
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] return getattr(trans, real_name)(*args, **kwargs)
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\utils\\translation\\trans_real.py", line 276, in ugettext
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] return do_translate(message, 'ugettext')
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\utils\\translation\\trans_real.py", line 266, in do_translate
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] _default = translation(settings.LANGUAGE_CODE)
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\utils\\translation\\trans_real.py", line 176, in translation
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] default_translation = _fetch(settings.LANGUAGE_CODE)
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\utils\\translation\\trans_real.py", line 159, in _fetch
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] app = import_module(appname)
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] File "C:\\Python27\\lib\\site-packages\\django\\utils\\importlib.py", line 35, in import_module
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] __import__(name)
[Tue May 31 09:57:49 2011] [error] [client 192.168.0.40] TemplateSyntaxError: Caught ImportError while rendering: No module named mySite.main
Can someone see the problem?
It is not finding your package (This is the obvious part).
On thing that has always worked for me is using the site module
import site
ALLDIRS = ['c:/wamp/www/']
for directory in ALLDIRS:
site.addsitedir(directory)
I also suggest you to use this activate_workingenv that works pretty well.
I hope that helps
It was a very, very simple thing.. The project folder name is case sensitive. I have changed the folder name to the orginal dev name and the project works like a charm.
Thanks for the help!
精彩评论