[Answered ]-How should I set up and deploy my django project that spans over multiple subdomains and multiple databases?

1👍

Perhaps you could usedjango-sudomains https://github.com/tkaemming/django-subdomains/

It is a middleware which creates a subdomain property for each request.

Since the functionality for each site is the same you could then just query for products based on sudomain requested. You could also assign users a subdomain.

All views would be the same except they would take into account this subdomain. This approach could work easy with 1 shared database where each model has a field that points to the subdomain or a shared database with subdomains being the database naem. https://docs.djangoproject.com/en/dev/topics/db/multi-db/#manually-selecting-a-database-for-a-queryset

1👍

I’ve built half a dozen applications that work like this (though none in python, but it’s really irrelevant in this case).

Serve everything from the same virtual host. Get the server name with urlparse Once you have the string you want to match, do a lookup in a master database for the database details which match your customer database (ie the hostname, username, password, etc.). Make sure you sanitize that value before querying on it.

I do think your best bet is separating your customers databases. Not only does this ensure that one database problem doesn’t bring down all your customer sites, it also allows you to put them on different servers.

Leave a comment