Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
177 views
in Technique[技术] by (71.8m points)

python - multiple instances of django on a single domain

I'm looking for a good way to install multiple completely different Django projects on the same server using only a single domain name. The point is that I want to browse to something like:

http://192.168.0.1/gallery/ # a Django photo gallery project
http://192.168.0.1/blog/ # a blogging project

This way, I can develop and test multiple django projects on the same server by just referring to different URLs. (note: I don't think this Django Sites module is what I am looking for because the projects need to be distinct). As an example, PHP kind of behaves in this way as I can install something like php-gallery and phpmyadmin on the same server, just with different URL paths.

Does anyone know of any good resources of how to setup multiple Django projects under multiple URLs on a single server using Apache (with either mod_python or mod_wsgi)? Things I'd be interested in knowing is how to setup the apache.conf, possible virtualenv setup, and changes to the urls.py to accommodate this. Most of the Django deployment examples that I see are for one application per domain or subdomain.
Any advice is much appreciated.

Thanks,
Joe

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I've been in situations where I couldn't use subdomains, and the way to handle this with Django is pretty simple actually.

Pretty much everything in your settings file will be just like a regular Django app, with the exception of making sure these settings include your project path:

MEDIA_URL = 'http://192.168.0.1/gallery/media/'
ADMIN_MEDIA_PREFIX = '/gallery/admin_media/'
SESSION_COOKIE_PATH = '/gallery'
LOGIN_REDIRECT_URL = '/gallery/'
LOGIN_URL = '/gallery/accounts/login/'
LOGOUT_URL = '/gallery/accounts/logout/'

The SESSION_COOKIE_PATH is critical to prevent all your apps on the same domain from rewriting each others cookies.

The above instructions should cover the Django side, but there's still more work to do on the web server side. For example, if you use apache+mod_wsgi you'll need to make sure each project has their own wsgi script that is loaded like this:

WSGIScriptAlias /gallery /path/to/gallery/apache/gallery.wsgi
Alias /gallery/media /path/to/gallery/media
Alias /gallery/admin_media /path/to/gallery/venv/lib/python2.6/site-packages/django/contrib/admin/media

etc.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...