Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6621131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:11:59+00:00 2026-05-25T21:11:59+00:00

My app serves multiple domains which I understand should be done by namespaces which

  • 0

My app serves multiple domains which I understand should be done by namespaces which I’m researching. Since multiple domains should have multiple analytics ID:s I get the analytics ID from the code but I want to make it even more configurable:

    if os.environ.get('HTTP_HOST').endswith('.br') \
        or os.environ['SERVER_NAME'].endswith('.br'):
        data[u'analytics'] = 'UA-637933-12'
else:
        data[u'analytics'] = 'UA-637933-18'

    self.response.out.write(template.render(os.path.join(os.path.dirname(__file__),
                            'templates', name + '.html'), data))

The above sets analytics ID to ..-12 if it’s my brazilian domain and to the other ID …-18 if it is my dot com. But this is only for 2 domains and it’s not easiliy generalizable. How can I achieve this function in a more scientific and scalable way so that it becomes easy to add my application to a domain without manually adding the domain to my application?

I suppose namespaces is the way to go here since the domains are google apps domains but I don’t understand how to use namespaces:

def namespace_manager_default_namespace_for_request():
  """Determine which namespace is to be used for a request.

  The value of _NAMESPACE_PICKER has the following effects:

  If _USE_SERVER_NAME, we read server name
  foo.guestbook-isv.appspot.com and set the namespace.

  If _USE_GOOGLE_APPS_DOMAIN, we allow the namespace manager to infer
  the namespace from the request.

  If _USE_COOKIE, then the ISV might have a gateway page that sets a
  cookie called 'namespace', and we set the namespace to the cookie's value
  """
  name = None

  if _NAMESPACE_PICKER == _USE_SERVER_NAME:
    name = os.environ['SERVER_NAME']
  elif _NAMESPACE_PICKER == _USE_GOOGLE_APPS_DOMAIN:
    name = namespace_manager.google_apps_namespace()
  elif _NAMESPACE_PICKER == _USE_COOKIE:
    cookies = os.environ.get('HTTP_COOKIE', None)
    if cookies:
      name = Cookie.BaseCookie(cookies).get('namespace')

  return name

I suppose I should use the namespace manager, get the namespace and set the analytics ID according to the namespace but how?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:11:59+00:00Added an answer on May 25, 2026 at 9:11 pm

    The simplest way to do this is with a Python dict:

    analytics_ids = {
      'mydomain.br': 'UA-637933-12',
      'mydomain.com': 'UA-637933-18',
    }
    
    data['analytics'] = analytics_ids[self.request.host]
    

    If you have other per-domain stats, you may want to make each dictionary entry a tuple, a nested dict, or a configuration object of some sort, then fetch and store it against the current request for easy reference.

    If you want to be able to reconfigure this at runtime, you could use a datastore model, but that will impose extra latency on requests that need to fetch it; it seems likely to me that redeploying each time you add a domain isn’t likely to be a problem in your case.

    Namespaces are tangential to what you’re doing. They’re a good way to divide up the rest of your data between different domains, but they’re not useful for dividing up configuration data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My gae app serves multiple domains by if..else.. conditions rather than namespaces. I see
I have multiple app processes that each connect to servers and receive data from
I have a rail app that serves multiple domain_name and is deployed by nginx
This is about a web app that serves images. Since the same request will
Is it possible to have two app.config files where one app.config serves as a
Im building a Grails app that will have multiple similar websites (each it's own
I want to deliver events from a server application to multiple clients. Since I'm
I have a WCF client/server app which is communicating over HTTP using the WSHttpBinding.
I have a single Rails 2.2.2 app that I want to 'share' with multiple
from multiprocessing import Process a=Process(target=worker, args=()) a.start() I am making a multiple worker-process app

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.