views:

65

answers:

2

Hey,

I am new to django and python and am trying to figure out how to modify an existing app to run multiple shops through a single domain.

Django's sites middleware seems inappropriate in this particular case because it manages different domains, not sites run through the same domain, e.g. : domain.com/uk domain.com/us domain.com/es etc.

Each site will need translated content - and minor template changes. The solution needs to be flexible enough to allow for easy modification of templates.

The forms will also need to vary a bit, e.g minor variances in fields and validation for each country specific shop.

I am thinking along the lines of the following as a solution and would love some feedback from experienced django-ers:

In short: same codebase, but separate country specific urls files, separate templates and separate database

  1. Create a middleware class that does IP localisation, determines the country based on the URL and creates a database connection, e.g. /au/ will point to the au specific database and so on.

  2. in root urls.py have routes that point to a separate country specific routing file, e..g

(r'^au/',include('urls_au')), (r'^es/',include('urls_es')),

  1. use a single template directory but in that directory have a localised directory structure, e.g. /base.html and /uk/base.html and write a custom template loader that looks for local templates first. (or have a separate directory for each shop and set the template directory path in middleware)

  2. use the django internationalisation to manage translation strings throughout

  3. slight variances in forms and models (e.g. ZA has an ID field, France has 'door code' and 'floor' etc.) I am unsure how to handle these variations but I suspect the tables will contain all fields but allowing nulls and the model will have all fields but allowing nulls. The forms will to be modified slightly for each shop.

Anyway, I am keen to get feedback on the best way to go about achieving this multi site solution. It seems like it would work, but feels a bit "hackish" and I wonder if there's a more elegant way of getting this solution to work.

Thanks, imanc

+1  A: 

There's no reason you can't the sites framework with multiple Django installations served from different subdirectories under the same domain.

And as mvid says, please accept some previous answers.

Daniel Roseman
wow - apologies. I didn't know I needed to accept answers!Thanks for the tip re's sites.
A: 

OK I have done some further digging and it seems that the Django sites framework is not suitable for the same domain but with different paths:

www.mydomain.com/uk
www.mydomain.com/au
etc.

The two other options are an apache/wsgi set up where a separate wsgi and settings.py is referenced for each subdirectory. This seems a bit cumbersome; I don't really want to have to be reconfiguring apache each time I deploy a new shop. Also it'd make maintaining the local dev, online dev, staging and live versions of the site more hassle.

I think given this situation the best solution is to look at a middleware class that keeps track of country code and somehow changes database settings and root urls.py. Then each app is going to have to be aware of its current base url for things like form actions and links and so on.