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
566 views
in Technique[技术] by (71.8m points)

deployment - Is it possible to host multiple django projects under the same domain?

I need to put different Django projects with Django CMS under the same domain, for example:

  • example.com/2012/
  • example.com/2014/

Normally I am using virtualenv and mod_wsgi for each domain/project. I will need different databases, media files, and Django versions.

Putting projects under different subdomains is not an option here.

Is it possible to do? How should I setup the server? Are there any caveats I should know?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Yes.

You can configure Apache / mod_wsgi to rewrite URLs and to direct them to different WSGI files. This allows you to setup entirely different virtualenvs, databases and Django versions for each site. For example:

WSGIScriptAlias /2012/ /location/to/my/files/website1.wsgi
WSGIScriptAlias /2014/ /location/to/my/files/website2.wsgi

Each of these WSGI files can then direct execution to files in a particular virtualenv with their own Django version and settings.

If you can loosen the constraint that you need different Django version then you can use the django.contrib.sites framework. This allows you to define multiple Site objects, once for each "website". You can then associate content with each of the sites while running one installation of Django.


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

1.4m articles

1.4m replys

5 comments

57.0k users

...