My solution to this is a custom middleware that rewrites the path
according the subdomain, before url parsing and getting views:
This is a short extract:
class URLRewriteMiddleware(object):
"""Middleware that manages urls with subdomains
"""
def process_request(self, request):
"""change path
(x).example.com/(y) -> example.com/subdomains/(x)/(y)
exception: www.example.com
"""
if settings.SUBDOMAINS_SUPPORTED:
site = Site.objects.get_current()
subdomain = request.META['HTTP_HOST'][:-len(site.domain)-1]
if subdomain and subdomain!="www":
path = request.path[len(settings.ROOT_DIR)]
request.path = "%s%s%s/%s" % (settings.ROOT_DIR,
settings.SUBDOMAIN_MNG_DIR, subdomain, path)
return None
My settings variables:
ROOT_DIR - either "/" or "/projectname/" depending on how my project
is accessed - under some domain directly or in some directory of
localhost.
SUBDOMAINS_SUPPORTED - Are subdomains supported on that server? True/False
SUBDOMAIN_MNG_DIR - the (x) directory to which all the query is added
Regards,
Aidas Bendoraitis [aka Archatas]
On 3/24/07, johnny <[EMAIL PROTECTED]> wrote:
>
> How do I route subdomains style url: http://api.mysite.com/ ?
>
> Thank you.
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---