Printing the domain as a variable within a template

25 views
Skip to first unread message

J

unread,
May 3, 2012, 5:05:23 PM5/3/12
to web...@googlegroups.com
Hi there,

I have a simple application running on webapp and I am trying to retrieve the domain within a template in order to programatically change a url printed to screen i.e. when running locally it'll be http://localhost:8080 but when deployed it'll be http://www.example.com. Thus far I have discovered the {{path}} variable, however this prints the current path without the domain - is there a similar variable that will enable me to print the domain bit?

Cheers,
J

Niklas Rosencrantz

unread,
May 3, 2012, 5:32:21 PM5/3/12
to web...@googlegroups.com
I think what you're looking for is self.request.host that you can pass on as a variable to your template, or the whole request object and then get the host name in your template by {{request.host}}
Cheers

J

unread,
May 3, 2012, 6:22:03 PM5/3/12
to web...@googlegroups.com
Thanks for the speedy reply Niklas. 

I realise I can pass it through as a variable - I was just wondering if there was a way to do that without adding code - i.e. {{path}} works without me having to pass anything as it seems to be a variable which just exists within the framework. I was wondering if there was another secret variable like {{host}} which could do the same thing...but I guess not else you would have said :)

J
Reply all
Reply to author
Forward
0 new messages