Problems with Django and Apache

I am trying to get Django and Apache to work together using Mod_wsgi, and currently I am getting the following errors:

[Thu Jul 15 12:52:38 2010] [error] [client 10.100.50.73] mod_wsgi (pid=4803): Target WSGI script '/home/webdev/websites/virtualenvs/polaris/polaris_project.py' cannot be loaded as Python module.
[Thu Jul 15 12:52:38 2010] [error] [client 10.100.50.73] mod_wsgi (pid=4803): Exception occurred processing WSGI script '/home/webdev/websites/virtualenvs/polaris/polaris_project.py'.
[Thu Jul 15 12:52:38 2010] [error] [client 10.100.50.73] Traceback (most recent call last):
[Thu Jul 15 12:52:38 2010] [error] [client 10.100.50.73]   File "/home/webdev/websites/virtualenvs/polaris/polaris_project.py", line 8, in <module>
[Thu Jul 15 12:52:38 2010] [error] [client 10.100.50.73]     import django.core.handlers.wsgi
[Thu Jul 15 12:52:38 2010] [error] [client 10.100.50.73] ImportError: No module named django.core.handlers.wsgi

My apache conf looks like

Alias /polaris_django/media/ "/home/webdev/websites/virtualenvs/polaris/polaris/static/"
WSGIScriptAlias /polaris_django /home/webdev/websites/virtualenvs/polaris/polaris_project.py
WSGIApplicationGroup %{GLOBAL}

<Directory "/home/webdev/websites/virtualenvs/polaris">
        Order deny,allow
        Allow from all
</Directory>

My Mod_WSGi file looks like

import os, sys

sys.path.append('/home/webdev/websites/virtualenvs/polaris')
sys.path.append('/home/webdev/websites/virtualenvs/polaris/polaris/apps')
sys.path.append('/home/webdev/websites/virtualenvs/polaris/polaris/extra_settings')
os.environ['DJANGO_SETTINGS_MODULE'] = 'polaris.settings'
print >> sys.stderr, sys.path
import django.core.handlers.wsgi

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

How can I get apache to serve Django properly?

+3
source share
4 answers

It looks like you are using virtualenv - you need to activate it in the WSGI script in order to properly configure the paths.

activate_this = os.path.join("path/to/my/virtualenv", "bin/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))
+5
source

It seems that Django is not in your way ... can you post the value of your sys.path?

+2
source

, apache python, sys.path. sys.path?

+1

Django? Python :

import django
print django.__file__

sys.path /usr/lib/python 2.6 /usr/local/lib/python2.6, .

, Django, - , Python, , mod_wsgi Django. mod_wsgi, . Django , Apache .

, :

http://blog.dscpl.com.au/2010/06/sydney-pycon-modwsgi-talk-slides.html

, , ..

+1
source

Source: https://habr.com/ru/post/1754848/


All Articles