2

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?

Aidas Bendoraitis
  • 3,965
  • 1
  • 30
  • 45

1 Answers1

5

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.

Simeon Visser
  • 118,920
  • 18
  • 185
  • 180
  • As I wrote before, that will be two different projects with different Django versions: one of them as archived website and another one as actual website. So I won't be using the sites framework to separate them. – Aidas Bendoraitis Nov 20 '13 at 21:31
  • @AidasBendoraitis that's fair, I just mentioned it to make you aware. In that case the first setup with multiple WSGI settings should do what you need. – Simeon Visser Nov 20 '13 at 21:33
  • How will I need to define urls.py for those projects? Starting with `"^2012/"` or only what goes after that? – Aidas Bendoraitis Nov 20 '13 at 21:38
  • @AidasBendoraitis only what goes after that. Apache would take care of the year part. – Simeon Visser Nov 20 '13 at 22:40
  • With Django 1.3.3 reverse("any_view") returns a view without "/2012/" prefix so administration and all other views with forms don't work. Does this issue still appear with newer Django versions? – Aidas Bendoraitis Mar 26 '14 at 16:00