Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Using dynamic subdomains with pyramid
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Alejandro Jatib  
View profile  
 More options Jul 12 2012, 11:51 pm
From: Alejandro Jatib <aja...@gmail.com>
Date: Thu, 12 Jul 2012 20:51:02 -0700 (PDT)
Local: Thurs, Jul 12 2012 11:51 pm
Subject: Using dynamic subdomains with pyramid

Hey folks,
I want to use dynamic subdomains as follows:
name1.domainapp.com
name2.domainapp.com
nameX.domainapp.com

When someone enters in these directions should be redirected to:
domainapp.com/name1
domainapp.com/name2
domainapp.com/namex

I tried several examples I found and I end up doing this:

in __init__.py:

    def pregen(request, elements, kw):
        #kw['_app_url'] = 'http://www.domainapp.com/' +
request.host.split('.')[0]
        return elements, kw

    def req_sub(info, request):
        return request.host.split('.')[0] != 'www'

    config.add_route('sub_only', '/{id:.*?}',
                 custom_predicates=(req_sub,),
                 #pregenerator=pregen
                 )

in views.py:

@view_config(route_name='sub_only')
def Subdomain(request):
        # redirect the user to "http://sub.example.com", regardless of
whether
        # request.host is "example.com" or "sub.example.com"
        return HTTPFound(location='http://www.domainapp.com/' +
request.host.split('.')[0])

Any suggestions to make it better?

Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonathan Vanasco  
View profile  
 More options Jul 13 2012, 11:00 am
From: Jonathan Vanasco <jonat...@findmeon.com>
Date: Fri, 13 Jul 2012 08:00:21 -0700 (PDT)
Local: Fri, Jul 13 2012 11:00 am
Subject: Re: Using dynamic subdomains with pyramid
I just do the URL rewriting like this on my proxy server or load
balancers.

It's way easier to just have nginx , varnish, etc handle this.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alejandro Jatib  
View profile  
 More options Jul 13 2012, 3:34 pm
From: Alejandro Jatib <aja...@gmail.com>
Date: Fri, 13 Jul 2012 12:34:28 -0700 (PDT)
Local: Fri, Jul 13 2012 3:34 pm
Subject: Re: Using dynamic subdomains with pyramid

I forget to say that i was using pyramid_appengine and hosting my app in
appengine.

El viernes, 13 de julio de 2012 00:51:02 UTC-3, Alejandro Jatib escribió:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Merickel  
View profile  
 More options Jul 13 2012, 3:38 pm
From: Michael Merickel <mmeri...@gmail.com>
Date: Fri, 13 Jul 2012 14:38:00 -0500
Subject: Re: Using dynamic subdomains with pyramid

If you can't do this on the web server as Jonathan suggested then I would
do it as a custom middleware that wraps your Pyramid app. It could check
the request's host and mutate the script_name/path_info as necessary before
it gets to Pyramid.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »