My gae app serves multiple domains by if..else.. conditions rather than namespaces.
I see someone else solved it with namespaces
“I have a single app with multiple namespaces defined.
I’d like to set up multiple domains
a.com b.com c.com
and have the app detect the domain and write the domain’s data into
its respective namespace.”
I don’t know how to do it with namespaces and I want a better way to add a domain to the app for settings like content and languages. For example sending an email via a form then I use just a condition instead of namespace.
class FileUploadHandler(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
adminemail = 'admin@domain1.com' if gethost() is 'domain1' else 'admin@domain2.com'
message = mail.EmailMessage(sender=admin_email, subject=self.request.POST.get('subject'))
message.body = ...
message.to='info@domain...
message.send()
self.redirect('/customer_service.htm')
I use same workaround for queries, localization and in some cases even which template to render to while I should be able to make all domains able to be based on same templates and differ only by content so that my app doesn’t hard-code the domains and other settings that should be easy to add and change.
Are namespaces a great idea in this case? The way a managed the problem with different domains so far is a variable for the entity which domains it came from
if util.get_host().find('my-dot-com') > 0:
url = 'www.my-dot-com.com'
I have a function that defines what I mean but it may confuse http://www.domain.com with domain.com or have problems with subdomains
def get_host():
return os.environ.get("HTTP_HOST", os.environ["SERVER_NAME"])
I’d be glad to know any idea if you have, or if I’m mistaken and shouldn’t use namespaces in this case.
Thanks
Yes, namespaces are ideally suited to what you’re doing. Simply store configuration data like admin emails in a per-domain configuration record, and store all the records for a given domain in a namespace named after that domain.