Database per subdomain

40 views
Skip to first unread message

Ruud Schroen

unread,
Jul 29, 2014, 8:23:03 AM7/29/14
to web...@googlegroups.com
Hi list,

I'm working on a portal where people can look for healthcare in a given municipality.

Imagine if each municipality has it's own portal, for example:


What would be the most efficient way to fetch a different database for different subdomains?

Massimo Di Pierro

unread,
Jul 29, 2014, 9:31:50 AM7/29/14
to web...@googlegroups.com
very easy:

if request.env.host_name == 'domain1': db_uri='sqlite://domain1.db'
elif request.env.host_name == 'domain2': db_uri='sqlite://domain2.db'
else: raise HTTP(404)

db = DAL(db_uri)

Ruud Schroen

unread,
Jul 29, 2014, 9:33:58 AM7/29/14
to web...@googlegroups.com
That was indeed easy. Thanks!


--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/2O1rf-_yTOA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Massimo Di Pierro

unread,
Jul 29, 2014, 11:36:28 AM7/29/14
to web...@googlegroups.com
Now somebody tries that with Django. ;-)
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages