是否可以在同一个域下托管多个 django 项目? [英] Is it possible to host multiple django projects under the same domain?

查看:24
本文介绍了是否可以在同一个域下托管多个 django 项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将不同的Django项目与Django CMS放在同一个域下,例如:

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

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

通常我为每个域/项目使用 virtualenv 和 mod_wsgi.我需要不同的数据库、媒体文件和 Django 版本.

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?

推荐答案

是.

您可以配置 Apache/mod_wsgi 来重写 URL 并将它们定向到不同的 WSGI 文件.这允许您为每个站点设置完全不同的虚拟环境、数据库和 Django 版本.例如:

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

然后,这些 WSGI 文件中的每一个都可以使用自己的 Django 版本和设置直接执行特定 virtualenv 中的文件.

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

如果您可以放松需要不同 Django 版本的约束,那么您可以使用 django.contrib.sites 框架.这允许您为每个网站"定义多个 Site 对象.然后,您可以在运行一次 Django 安装时将内容与每个站点相关联.

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.

这篇关于是否可以在同一个域下托管多个 django 项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆