English 中文(简体)
Django, is possible to run two different versions?
原标题:

I have a server on which I have two sites built with Django and Python, one site is major site is build with an older version of django, the other with the newer release, I have upgraded to the new release and major aspects of my other site have broken, is it possible to tell the site to use a different version in say the python path? in the virtualhost?

I am desperate for help!

Some more info, it is on a linux and server users mod python, here is what I am trying with the vitrualhost

<Location "/">
        SetHandler python-program
        PythonHandler django.core.handlers.modpython
        SetEnv DJANGO_SETTINGS_MODULE website.settings
        SetEnv PYTHON_EGG_CACHE /var/cache/pyeggcache
        SetEnv PYTHONPATH "sys.path + [ usr/lib/python2.6/site-packages/django2 ]"
        PythonDebug On
        PythonPath "[ /var/www/website_live/src ] + [ /var/www/webiste_live/src/website ] + sys.path"
    </Location>

I have replaced the website name with website my seperate version of django lives at /usr/lib/python2.6/site-packages/django2

最佳回答

When you have more than one site on a server, you should consider using something like virtualenv.

Using that you can setup different virtual environments and place site specific packages and such in there, instead of messing up your site-packages folder. It also makes development a lot easier as you easily can setup these environments on your local with specific versions of whatever you use.

This quickly becomes very handy if you use other apps, and this is something that Pinax uses very heavily. The easiest way to handle packages and versions is simply to create a requirements file.

问题回答

Yes, you could. I have blogged about this at length over here.

Of course it is, but it will require a bit of nestling. It depends mainly on which server you use.

The key point is the $PYTHONPATH. This variable stores, where Python looks for modules to embed. If you use

import django.conf

it really looks through all dirs in $PYTHONPATH and searches for a folder called django.

So the key is to manipulate $PYTHONPATH depending on where the request goes to. If you happen to use mod_python and Apache, it could look like this:

<VirtualHost *:80>
    DocumentRoot "/var/htdocs/old_django_project"
    ServerName old-django
    PythonPath "sys.path + [ /var/software/old_django ]"
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/var/htdocs/new_django_project"
    ServerName new-django
    PythonPath "sys.path + [ /var/software/new_django ]"
</VirtualHost>

Then, visiting http://old-django/ brings you to the old django instance, and the new-django likewise.

It is possible, but in my experience of an environment that used different versions of both Django and Python it tends to end up getting messy, especially if you have more than one developer working on the projects. Each developer then needs to maintain two versions of Django and remember which features they can and cannot use.

I use Wigwam for this sort of thing. It s a heavy-handed approach — there s a separate build of each of Apahce, Python, Django, etc. — but it works quite well.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签