This tutorial shows you how to get your domain name(base url) from address bar in Google AppEngine, using self and urlparse
This is simple tutorial, more like a snippet. That shows you how you can get your domain from address bar. For example you are browsing our site and your URL in address bar is "/tutorial/get-self-base-url-appengine-urlparse". With this script you can get the domain out of it, that would be "www.browse-tutorials.com".
Base URL:
This is a part of my python file of my Google AppEngine application. I wanted to use base url in my view and this is how I do it. Don't forget to add the library.
This is a part of my python file of my Google AppEngine application. I wanted to use base url in my view and this is how I do it. Don't forget to add the library.
The same thing in Python console.Source code viewer
from urlparse import urlparse ### def get(self): template_values = { #This is the part where we get base_url from #self and using urlparse we get the domain name. 'base_url': urlparse(self.request.url).netloc, } path = os.path.join(os.path.dirname(__file__), 'template/index_card.html') self.response.out.write(template.render(path, template_values)) ### Programming Language: Python
Source code viewer
user_name@computer_name:~$ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from urlparse import urlparse >>> url = '/tutorial/get-self-base-url-appengine-urlparse' >>> url '/tutorial/get-self-base-url-appengine-urlparse' >>> url_array = urlparse(url) >>> url_array ParseResult(scheme='http', netloc='www.browse-tutorials.net', path='/tutorial/get-self-base-url-appengine-urlparse', params='', query='', fragment='') >>> base_url = url_array.netloc >>> base_url 'www.browse-tutorials.net' >>>Programming Language: Text