Forums

Several sites/domains & one Django project

Hello Guys,

I would like to run several domains from one Django project.

  • same data base
  • same authentification
  • same admin
  • different apps

I understood that I have to create two different pythonanywhere web apps anyways, but that's not the issue.

Then I don't manage to bring all the pieces together in my head.

  • two different settings files, but how ?
  • using the Django Sites framework ?
  • what about ALLOWED_HOSTS ? of course in the end the 2 hosts should be allowed, but not for all the apps in the projects. The goal is to share the global infrastructure, database and code base, but avoid the conflicts: domain1/appname should work, but domain2/appname shouldn't.

I don't know if I'am 100% clear. If not, just tell me and I'll try to clarify further.

If it is clear enough, I would really appreciate some help to understand the core concepts and get it right.

Thank you very much in advance for your help and happy new year ! Lionel

Since you'd set DJANGO_SETTINGS_MODULE env variable in the wsgi file anyway, you may use different files and point to them respectively in your different wsgi files for different accounts. Which database do you want to use?

Yes, that's right. I am using Postgres. I guess I just have to point to the same database.

Yes, that is correct

Okay thanks a lot ! will give it a shot

Hi again :-) What about the postactivate file ?

Specifically, the DJANGO_SETTINGS_MODULE is set to a seetings module which is obvisously the original one and not the one for the second domain

I would like to be able to git pull once, then reload the 2 pythonanywhere web apps. How will this affect the virtualenv ?

If you want the web apps to use the same virtualenv, then you cannot have different postactivate files for each web app. Either apply the different settings from the postactivate in a different way or use different virtualenvs if you want to use postactivate to differentiate between your web apps.

I would like to use the same virtualenv for the 2 PA web apps. In fact, I would like to use the same db and same apps accross the 2 domains.

I guess the only diff between the 2 are root urls.py & allowed hosts

I don't see how to do this properly. When migrating from my code base, I guess it wouldn't work if some apps are not installed in the settings file. So both settings files should have all the django project apps installed.

Or is possible to have one settings file for postactivate and different settings files at the wsgi config level to be able to differentiate regarding root_urls, allowed hosts and even maybe the installed apps ?

Additional issue, I've been trying to add a second Site object but got a duplicate key value error. The first Site object was created by the initial migration from Django cookie cutter. If there is an obvious answer to this, I'll take it.

If you want to use a different settings file between your webapps, then do not set it in postactivate, set it in your wsgi file.

When you're adding the second Site object, make sure it has a different name and primary key.

Yes thank you. Regarding the Site object, of course, what's weird is that doing it from the admin panel dosen't work, throwing a duplicate key value error.

Now it's worked, via the admin panel. All good

Thanks for letting us know!