Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current domain name with Python/GAE?

Current url is

http://myapp.appspot.com/something/<user-id>

or

http://127.0.0.1:8080/something/<user-id>

How in my python code I can get http://myapp.appspot.com/ or http://127.0.0.1:8080/? This is need for dynamic links generation, for ex., to http://myapp.appspot.com/somethingelse.

self.request.path returns the whole path.

like image 933
LA_ Avatar asked Apr 30 '11 13:04

LA_


2 Answers

self.request.host_url

like image 116
Drew Sears Avatar answered Oct 12 '22 14:10

Drew Sears


I think you want app_identity.get_default_version_hostname().

If an app is served from a custom domain, it may be necessary to retrieve the entire hostname component. You can do this using the app_identity.get_default_version_hostname() method.

This code: logging.info(app_identity.get_default_version_hostname())

prints localhost:8080 on the development server.

like image 23
cyrf Avatar answered Oct 12 '22 14:10

cyrf