Is it possible to host multiple django projects un

2020-02-11 11:21发布

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条回答
\"骚年 ilove
2楼-- · 2020-02-11 12:04

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.

查看更多
登录 后发表回答