django app engine multiple domains, multiple settings files - django

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

Related

How to run multiple sites from one instance of Django?

I am using Django as the back end and Nuxt as the front end, with Postgres as the database. I would like to have different tables/databases for each domain.
The Django code and the Nuxt code will be the same for all sites.
The way the app is set up, it requires different domains to have different databases or at least different tables.
At the moment, I am thinking I need to create a separate installation of Django/Nuxt for each domain. But I am wondering if there is a better way?
Setting up different Code bases for every domain is not a good idea at all. I had an app that was set up that way and soon we were struggling to maintain the same code and DB structure for all the different domains. After a few domains, it will become tricky.
I would suggest developing a multi-tenant SAAS based app, where you can have multiple tenants running the same Django/Nuxt code but having different schemas in the Postgres, So your database for different domains will be completely separate from each other. I would suggest using django tenant schemas for this. Even if it takes you some time to set it up, I would suggest doing it. It will save a great deal of time for you in the future.

Subdomain hosting with Django + Nginx +Gunicorn

I am developing a web app using django for server-side. It has clients in android, ios and frontend. I was thinking of using subdomains for differentiating the urls of these clients. The differentiation is due to the fact that responses to urls are different for different clients.
I was hoping of being able to do using subdomains like android.example.com, ios.example.com...etc. My subdomains are fixed.
Can you help regarding what approach I should take to achieve this. Some options I have read are
Hosting two different project with same database.(Looks quite good for me, but may not be the optimum)
Hosting on same instance using sites framework.(Not sure as to how good this option is)
Hosting using virtual-host(Really Not able to understand how to achieve this).
Using a Sub-domain Middleware, as mentioned in many of answers and also in some Django Snippets.
Please help me with the best option and if possible with links to some tutorials as to how to achieve it. Thanks.
"Using the sites framework" is somehow the same as hosting two projects with the same database. If you would use the sites framework you would have seperate instances for each subdomain which share the same code base and data base, but have to differ in one setting in the first place, which is SITE_ID.
If you're able to run multiple instances this for sure has some advantages:
You don't need additional processing via a middleware
You can easily choose different settings for each site, eg. different template paths, use different middleware etc, even customize urls per project if necessary
You're doing already some kind of load-balancing, as you're directing requests to seperate instances, also if one site crashes it shouldn't affect the others
If you can only run one instance I guess your only choice is using something like a middleware, eg. django-mobile then is maybe something to look in as it offers you some good toolset for determining the type of client etc...
But besides that note that it might not always be the best practice to have seperate domains with the same content when it comes to SEO.

Multiple domains with shared codebase but different data using Django

What I'm trying to do is best explained by looking how wordpress.com works:
each blog is assigned to a new subdomain, but users can use their own domain as well. Custom domains could be assigned using a simple web interface
each blog has its own contents, theme, etc
all blogs share the same codebase
Is it possible to do the same thing in Django?
I'm not interested in implementing subdomains, but I want the other features.
It is important to me to find a way that domains don't have to be hardcoded in a configuration file in order to work. The dynamic nature of domain assignment makes managing large number of domains possible. It would be ideal if domain matching could be done against a database table.
I use nginx and uwsgi.
Yes but it will require more work in Django compared to out-of-the box Wordpress install but will offer you more flexibility.
You might want to take a look at django sites. However I don't think it will be able to do everything you are trying to do.
A more modular system would be for you to write a script which when invoked will bootstrap a new db schema, new virtuelenv, install all necessary things into it, add a site config for the new site to nginx/apache and then restart the nginx/apache. The code can be from the same directories, except since each site will run on it's own virtualenv, it will be much more secure, reliable and fault tolerant. This however as you can see will require some work but I depending on your requirements, it is the most flexible way.

Multiple sites with 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.

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.