1

I'm trying to deploy django using wsgi. But its not working. Will you please help me ? thank you

django.wsgi.py

#!/usr/bin/python
import os, sys
sys.path.append('/home/me/project')
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

/etc/apache2/sites-available/default

    <VirtualHost *:80>

  ServerName www.me.org
  ServerAlias *me.org

  Alias /admin_media /usr/lib/python2.4/site-packages/django/contrib/admin/media

  <Location /admin_media>
    Order allow,deny
    Allow from all
  </Location>

  Alias /media /var/www/media/

  <Location /media>
    Order allow,deny
    Allow from all
  </Location>

  WSGIScriptAlias / /home/me/project/apache/django.wsgi

  WSGIDaemonProcess me processes=2 maximum-requests=500 threads=1
  WSGIProcessGroup me

</VirtualHost>

Error Message

   /etc/init.d/apache2 restart
Syntax error on line 3 of /etc/apache2/sites-enabled/me:
Invalid command 'PythonHandler', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.
   ...fail!

UPDATE :Strange /etc/apache2/sites-enable/me

<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
PythonDebug On
PythonPath "['/home/me2'] + sys.path"
SetEnv DJANGO_SETTINGS_MODULE me.settings

Can I disable mod-python?

1
  • We're missing the file /etc/apache2/sites-enabled/me. Or is this a symlink to /etc/apache2/sites-available/default? Commented Dec 2, 2011 at 9:04

3 Answers 3

3

It should be obvious that your error message is coming from a different file than the one you have shown here - me rather than default. That file apparently has a reference to PythonHandler, which is a directive that belongs to mod_python which you don't seem to have installed (and shouldn't, as it is deprecated).

When you've fixed that error - most likely by removing that file altogether - you'll have another one to fix in your wsgi file - you've added the project path to the pythonpath, but then referenced your settings as project.settings, so it won't be found. Either add the parent path instead, or reference settings as just settings.

Sign up to request clarification or add additional context in comments.

Comments

1

The /etc/apache2/sites-enable/me file is for modpython.

You're using mod_wsgi.

Therefore. Remove the /etc/apache2/sites-enable/me and follow the documentation provided here

https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/

2 Comments

I've removed /etc/apache2/sites-enable/me. Now I'm getting. The requested URL / was not found on this server.
@no_access: That's a separate question. Please open a new question providing the relevant details for your new problem. You'll probably need to create an Apache "Location" that directs requests to your Django instance. Please accept an answer to this question and start a new question that covers your new situation.
1

I'm not an expert at this stuff, but here is comparing to what I've got working. I'm using mod_wsgi instead of mod_python. What you have in "/etc/apache2/sites-enabled/me" I seem to have sepecified in my "django.wsgi.py" file, and I have no such files under sites-enabled.

To your django.wsgi.py you might need to add the path to your external libraries, and when I set the path for my project, my settings file is /var/myproject/src/myapp/settings.py, and I set the path to '/var/myproject/src', and the django_settings_module to myapp.settings. Here's what my myproject.wsgi file looks like:

#!/usr/bin/python
import os
import sys
sys.path.append('')
sys.path.append('/usr/local/lib/python2.7/site-packages')
sys.path.append('/usr/local/lib/python2.7/site-packages/Django-1.3-py2.7.egg')
... other external libs ..
sys.path.append('/var/myproject/myapp/src')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
os.environ['PYTHON_EGG_CACHE'] = '/tmp'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Here is what I've got for my wsgi.conf:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/var/myproject/"
    ServerName localhost
    ErrorLog "/var/myproject/logs/apache-error.log"
    CustomLog "/var/myproject/logs/apache-access.log" common

    Options ExecCGI FollowSymLinks MultiViews

    AddHandler wsgi-script .wsgi
    WSGIDaemonProcess asgportal
    WSGIProcessGroup asgportal

    Alias /static /var/myproject/media/static
    WSGIScriptAlias / /var/myproject/myproject.wsgi  # my django.wsgi.py file

    DirectoryIndex index.html index.cgi

    AddHandler cgi-script .cgi .pl
</VirtualHost>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.