has anyone ever used wildcard subdomains in their application? I need to come up with a way to 'localise' my application. When i say localise i mean anyone who goes to
I would do it using a middleware, eg.:
class StateCodeMiddleware(object): def process_request(self, request): bits = request.META['HTTP_HOST'].split('.') if len(bits) == 3 and len(bits) == 2: request.state_code = bits else: request.state_code = None # Or a redirect to the default state.
And then in any of your views, you can just check
request.state_code and fetch new items only for that state.
Edit: For development, the best method is to setup a local DNS server. Eg. dnsmasq is very easy to configure:
address=/.dev/127.0.0.1 # in dnsmasq.conf
*.dev point to localhost. You'll also have to configure your system to use the local DNS server (on UNIX systems you do this by placing
nameserver 127.0.0.1 into
Alternatively, you can list all the domain names in your /etc/hosts if it is a finite set:
127.0.0.1 ny.localhost, az.localhost # and so on