Multiple sites with Django - django

Let's imagine I have two sites foo.com and bar.com. They both are on the same server and now running separate Django instances and apache to serve it. Of course each Django instance eats the memory.
While mainly those sites are the same systems, but with different apps loaded - maybe it is possible somehow to have for example one Django instance running and have multiple sites using it? Then I will save memory for the one instance in a particular example.
It is possible to have different sites with their url.py files, loaded apps and so on? And if this is the right way to go?
Any tips, ideas are welcome.
Thanks,
Ignas

Yes it is definitely possible to have different sites with different urls.py and shared apps.
I had to share a backend data between multiple sites. I just created 2 wsgi config files. And 2 settings files. The sites are very smiliar and didn't warrant two seperate projects. This allows me to use one django project and backend between multiple sites. I don't quite know if this is what you were asking though...

My own research today on the same topic leads me to the conclusion that you'll most likely have to have only one settings.py per Django instance/process. And the sticking point there is only one MEDIA_URL and one MEDIA_ROOT, which means all your projects media will have to be in the same location. And actually Django 1.3 has a new static file process that just goes through all the media of your seperate apps and puts them in one spot because for some reason it demands that. If you're using earlier versions I guess you can do it by hand.
https://docs.djangoproject.com/en/dev/howto/static-files/

uWSGI can serve more applications from one instance.
See "Two Pinax site in two virtualenv in two virtualhost with only one uWSGI instance" in uWSGI examples and VirtualHosting Mode.

Related

django app engine multiple domains, multiple settings files

I'm new to Google App Engine and am trying to port my Django application to use that. I haven't been able to find too much on this and don't think multitenancy is what I'm looking for (seems to be for more or less identical apps with different data sources?), but my scenario is this:
I have multiple domains and currently have different settings file (with seperate WSGI files) which works great for my current Apache configuration, but I'm trying to migrate over to GAE and can't seem to figure out how to do something similiar based on domain name? Really, all I critically need is a seperate urls file based on the domain name (datastore is the same on both), although it would be ideal to have a separate settings file so I don't have to load unused apps, preprocessors, etc on sites that don't need them.
You can possibly have two different versions of the app, they both will use the same data store, since source code of both versions can be different, you can specify different configurations/settings for each of them.
coming to accessing different versions, you can either route through your dashboard/domain settings and/or fine tune it with help of traffic splitting
hope it helps

Django sites framework and Heroku

Just wanted to ask if this was an 'acceptable' use of the django sites framework and heroku - and if there would be any trouble running the two sites:
Main differences between sites will be templates, and some objects only published to one or other (or both) sites - notably users should be able to use both sites using their single account.
I have my one codebase. Any change in my settings.py file is dealt
with by using heroku config variables.
I set up database that can be shared (either on an EC2 or using
Heroku dedicated dbs)
I git push my code to two different Heroku Apps
Hey presto - one codebase, two running instances of Django, two separate sites.
Any issues with that?
I went into great depth to answer this question in another thread, you can see my answer here: Multiple Django sites with shared codebase and DB
The short answer is NO, don't use the sites framework, use git branches.

Multiple Django Sites, one server

I have multiple sites for the same client, on the same server, running django, e.g. fooplumbing.com and bazheating.org. These two sites would each have different django apps, that is the plumbing site shouldn't be able to access the heating apps, and vice versa. There are no objects shared between the two sites, and each needs its own separate admin site.
Is this possible through something like the sites framework, or would I need to have two separate apache instances running the sites? (Yes, I need to use apache - no choice)
It's a Linux server, so is there some clever way of using symlinks to do this? I'm pretty experienced with basic django development, but I have no clue when it comes to server management.
The sites framework won't help you - they should be served as completely separate WSGI applications.
But there's no need for separate Apache instances. Just configure Apache to serve separate VirtualHosts, each with its own WSGI file.

Can multiple Django sites share memory?

I'm using Apache + mod_wsgi daemon mode for running a Django site. When another site is added (new virtualhost), a second daemon appears.
Is there any way to let those sites share the same proces / memory?
It seems to wasteful to have ~20MB persistently in use per site.
Bonus points: how does this compare to PHP hosting? (especially Drupal/Joomla)
Have a look at Django sites framework.
http://docs.djangoproject.com/en/dev/ref/contrib/sites/
Other than that, the answer is no, as Django use global variables for configuration and so not possible to have same code base dynamically switch what site it runs as on a per request basis.

Multiple Django Instances on one AppEngine Server

For our project we host both the website and the actual webapp on one AppEngine instance. I separated them both nicely in different projects, but they all share the same settings file. It's becoming more and more clear to me that these should actually be independent django instances as they use different settings for middleware, template loaders, etc.
So I tried running two django instances on the same server (different handlers), but because django uses global variables for caching all over the place, which the AppEngine runtime caches between requests, I couldn't get this to work reliably. Did anyone successfully do this before?
Since you can run multiple app versions simultaneously, I would put this independent django instances in different app versions.