开发者

How to set up multiple django versions on single apache service?

开发者 https://www.devze.com 2023-04-10 09:30 出处:网络
I\'m using Windows XP and want to know how can I create multiple django versions on a single apache service through virtual host(of course).

I'm using Windows XP and want to know how can I create multiple django versions on a single apache service through virtual host(of course).

I'm trying to do that with one instance of python too. Should i create 1 instance of python for each django version or django needs only its eggs to work, so I can have several开发者_如何转开发 eggs in just one python version?


You can do something like this in your httpd.conf

NameVirtualHost 0.0.0.0:80
<VirtualHost 0.0.0.0:80>
    ServerName myserver.com
    ServerAdmin myemail@gmail.com
    DocumentRoot "/path/to/html/root"
    ErrorLog "/path/to/apache-error.log"
    CustomLog "/path/to/apache-access.log" common

    Options ExecCGI FollowSymLinks MultiViews

    AddHandler wsgi-script .wsgi
    WSGIDaemonProcess djangoapp1
    WSGIProcessGroup djangoapp1
    WSGIScriptAlias / /path/to/djangoapp1.wsgi

    Alias /static /path/to/static/files

    DirectoryIndex index.html index.cgi

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

NameVirtualHost 0.0.0.0:81
<VirtualHost 0.0.0.0:81>
    ServerName myserver.com
    ServerAdmin myemail@gmail.com
    DocumentRoot "/path/to/html/root"
    ErrorLog "/path/to/apache-error.log"
    CustomLog "/path/to/apache-access.log" common

    Options ExecCGI FollowSymLinks MultiViews

    AddHandler wsgi-script .wsgi
    WSGIDaemonProcess djangoapp2
    WSGIProcessGroup djangoapp2
    WSGIScriptAlias / /path/to/djangoapp2.wsgi

    Alias /static /path/to/static/files

    DirectoryIndex index.html index.cgi

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

And then, in your djangoapp1.wsgi/djangoapp2.wsgi script you can define the different django versions and applications:

#!/usr/bin/python
import os
import sys
sys.path.append('')
sys.path.append('/path/to/python2.7/site-packages')
sys.path.append('/path/to/python2.7/dist-packages/Django-1.3-py2.7.egg ')
... etc ...
sys.path.append('/path/to/djangoapp1/src')
os.environ['DJANGO_SETTINGS_MODULE'] = 'djangoapp1.settings'
os.environ['PYTHON_EGG_CACHE'] = '/tmp'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()


Method 1:

put django source anywhere you want and manually specify path to django source in your manage.py and wsgi.py:

import os
os.path.insert(0, 'path-to-django-source');

You can also use virtualenv. Virtualenv fixes paths for console apps automatically, however for wsgi.py you still have to write down path's manually.

Method 2:

Use zc.buildout and djangorecipe, it will do all the stuff for you including:

  • donwloads django
  • download other modules
  • creates wsgi.py at project-dir\bin\wsgi
  • creates manage.py at project-dir\bin\django.exe

All this is done with a single config file buildout.cfg- here you list your modules and other settings, and then you run a command: buildout -N.

However buildout might not be a good solution if you have tight deadlines because there will be things you'll need learn about it but if you are planning to do more python apps I definitely recommend trying it.

Here are some examples for django+buildout setup:

http://www.google.lt/search?q=django+buildout+template+OR+skeleton

An update to your comment

You cannot install two django versions system wide.

What you can do though is either:

  1. Do not install django, just drop the django-base/django folder into your project path. You will have to compile the internationalization files manually (if you use i18n):

     cd django\conf
     python ..\..\manage.py compilemessages
    
  2. Or, install django with python setup.py install, but use extra arguments to change installation destination. Python documentation covers few different methods.

0

精彩评论

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