I need to get django to send an email which contains a URL like this
http://www.mysite.org/history/
Where ‘history’ is obtained like so:
history_url = urlresolvers.reverse('satchmo_order_history')
history_url is a parameter that I pass on to the function that sends the email, and it correctly produces ‘/history/’. But how do I get the first part? (http://www.mysite.org)
Edit 1
Is there anything wrong or unportable about doing it like this? :
history = urlresolvers.reverse('satchmo_order_history')
domain = Site.objects.get_current().domain
history_url = 'http://' + domain + history
If you have access to an
HttpRequestinstance, you can useHttpRequest.build_absolute_uri(location):In alternative, you can get it using the sites framework:
Re: Edit1
I tend to use
urlparse.join, because it’s in the standard library and it’s technically the most Pythonic way to combine URIs, but I think that your approach is fine too.