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

人走茶凉 提交于 2019-12-18 05:24:18

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/20107145/is-it-possible-to-host-multiple-django-projects-under-the-same-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!