janrain dynamic hostname in url

67 views
Skip to first unread message

rjmolesa

unread,
May 19, 2012, 1:32:41 PM5/19/12
to web...@googlegroups.com
How can I get the host name that web2py is running on so that I can simply deploy a janrain enabled app without editing db.py each time

auth.settings.login_form = RPXAccount(request, 
api_key='...', 
domain='...', 
url = "http://" + application.hostname + "/%s/default/user/login" % request.application)

Anthony

unread,
May 19, 2012, 2:23:49 PM5/19/12
to web...@googlegroups.com
Try

url = URL('default', 'user', args='login', host=True, scheme=True)

That will construct a URL including the current host and the current scheme (i.e., http or https).

More generally, the current host can be found in request.env.http_host, and the current scheme in request.env.wsgi_url_scheme (request.is_https also indicates whether the scheme is https or not). See http://web2py.com/examples/simple_examples/status for more details about the request and response objects.

Anthony

Jon Molesa

unread,
May 19, 2012, 2:31:18 PM5/19/12
to web...@googlegroups.com
BOOM! Much thanks. I have changed it to read:

auth.settings.login_form = RPXAccount(request,
api_key='...',
domain='...',
url = URL('default', 'user', args='login', host=True, scheme=True) +
"/%s/default/user/login" % request.application)

and it's working!
--
Jon Molesa
rjmo...@gmail.com

Anthony

unread,
May 19, 2012, 6:17:37 PM5/19/12
to web...@googlegroups.com
url = URL('default', 'user', args='login', host=True, scheme=True) +
"/%s/default/user/login" % request.application)

URL('default', 'user', args='login', host=True, scheme=True) alone will produce http://yourdomain.com/yourapp/default/user/login, so there should be no need to add "/%s/default/user/login" % request.application, which will result in http://yourdomain.com/yourapp/default/user/login/yourapp/default/user/login. That will still work (the second /yourapp/default/user/login will just be interpreted as a set of request.args and ignored by web2py), but no need for it.

Anthony

Jon Molesa

unread,
May 19, 2012, 8:52:45 PM5/19/12
to web...@googlegroups.com
Thank you.
--
Jon Molesa
rjmo...@gmail.com
Reply all
Reply to author
Forward
0 new messages