开发者

how to run Django application in apache2

Hi All i am not able to run a django application in apache2 webserver. I have went through all the document but it still did not work for me.This is my Apache2's httpd.conf file

<Location "/mysite/">
  SetHandler python-program
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE mysite.settings
  PythonO开发者_运维问答ption django.root /mysite
  PythonPath "['/home/djangotest/mysite'] + sys.path"
  PythonDebug On
</Location>

My django project location is at /home/djangotest/mysite in which i am running the polls application. Is there something i have to mention in settings.py or urls.py for this to work in apache2 it works fine in the dev server. or is there configuration i have to do in apache2 to work


  1. Download and install http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz

  2. Add to the /etc/httpd/conf.d/ directory


<VirtualHost *:80>
  ServerName --insert--

  ErrorLog /home/djangotest/mysite/error_log
  CustomLog /home/djangotest/mysite/access_log combined

  UseCanonicalName Off

  WSGIScriptAlias /g2 /home/djangotest/mysite/mysite.wsgi
  WSGIDaemonProcess iproj processes=7 threads=1 display-name=%{GROUP}

</VirtualHost>
  1. Add to LoadModules secion in /etc/httpd/conf/httpd.conf

    LoadModule wsgi_module /usr/lib/httpd/modules/mod_wsgi.so

  2. Add to AddHandler section in /etc/httpd/conf/httpd.conf

    AddHandler wsgi-script .wsgi

  3. Make sure your the httpd user can access /home/djangotest/ as well as execute your python scripts

  4. Create a mysite.wsgi file:


import os
import sys

sys.path.append('/home/djangotest/mysite')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

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

Or as @Efazati said, read the manual ;)


Hopefuly this solves your final issue:

no module named mysite.urls but there is a file urls.py

Check your settings file for

ROOT_URLCONF = "mysite.urls"

This is the name of your urls file, I am guessing you dont have a module called mysite.urls.py ? It sounds like your property should read:

ROOT_URLCONF = "urls"


Try to add '/home/djangotest' to PythonPath:

<Location "/mysite/">

  SetHandler python-program
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE mysite.settings
  PythonOption django.root /mysite
  PythonPath "['/home/djangotest', '/home/djangotest/mysite'] + sys.path"

  PythonDebug On
</Location>

You need to add that if you import your project's files with the syntax .. The other guys here are right, though; switch to mod-wsgi if you can. Django's mod_python support will be deprecated very soon. http://docs.djangoproject.com/en/1.2/howto/deployment/modpython/

edit: mod_python support is deprecated in Django 1.3, and will be removed entirely on Django 1.5.


read the manual

http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜