Django and Routing SUBDOMAIN STYLE URL

2007-03-24 Thread johnny

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 django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Django and Routing SUBDOMAIN STYLE URL

2007-03-24 Thread Aidas Bendoraitis

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 django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Django and Routing SUBDOMAIN STYLE URL

2007-03-24 Thread johnny

How do you test the subdomin url style in Django development server?

Developer server is at:
http://127.0.0.1:8000/

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 django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Django and Routing SUBDOMAIN STYLE URL

2007-03-24 Thread Michael Cuddy

> 
> How do you test the subdomin url style in Django development server?

Since I control my own server and DNS, All of the subdomain URLs point to
the same IP.  I just have the dev server on my.ip.com:8000 (which means
that myother.ip.com and yetanother.ip.com are all CNAMEs for my.ip.com,
so the production host works, too (apache + mod_python)

--
Mike Cuddy ([EMAIL PROTECTED]), Programmer, Baritone, Daddy, Human.
Fen's Ende Software, Redwood City, CA, USA, Earth, Sol System, Milky Way.

"The problem with defending the purity of the English language is
that English is about as pure as a cribhouse whore. We don't just
borrow words; on occasion, English has pursued other languages down
alleyways to beat them unconscious and rifle their pockets for new
vocabulary." -- James D. Nicoll

   Join CAUCE: The Coalition Against Unsolicited Commercial E-mail.
  

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Django and Routing SUBDOMAIN STYLE URL

2007-03-25 Thread johnny

I have tried:

http://api.localhost:8000/
http://api.127.0.0.1:8000/

This is not working on my windows machine (using development server,
not apache+mod_python).

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 django-users@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Django and Routing SUBDOMAIN STYLE URL

2007-03-25 Thread Michael Cuddy

> I have tried:
> 
> http://api.localhost:8000/
> http://api.127.0.0.1:8000/
> 
> This is not working on my windows machine (using development server,
> not apache+mod_python).

You have two choices.  If you have access to /etc/hosts on the
server, you can define somehost.localhost and someother.localhost as
aliases for localhost

and then you should be able to access via http://somehost.localhost:8000  
and http://someother.localhost:8000

OR ... (and this is what I do, because my web client is not on my dev
host)

You can run the dev server so that it binds to all IP addresses on the
host:

python manage.py runserver 0.0.0.0:8000

and then your CNAMEs should work.

http://somehost.example.com:8000/, http://someother.example.com:8000/

--
Mike Cuddy ([EMAIL PROTECTED]), Programmer, Baritone, Daddy, Human.
Fen's Ende Software, Redwood City, CA, USA, Earth, Sol System, Milky Way.

"The problem with defending the purity of the English language is
that English is about as pure as a cribhouse whore. We don't just
borrow words; on occasion, English has pursued other languages down
alleyways to beat them unconscious and rifle their pockets for new
vocabulary." -- James D. Nicoll

   Join CAUCE: The Coalition Against Unsolicited Commercial E-mail.
  

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~--~~~~--~~--~--~---