1
一个完整的URL我需要的Django发送包含这样如何构建在Django
http://www.mysite.org/history/
一个网址,“历史”是像这样获得的一封电子邮件:
history_url = urlresolvers.reverse('satchmo_order_history')
history_url是我传递给发送电子邮件的函数的一个参数,它正确地生成'/ history /'。但是,我如何获得第一部分? (http://www.mysite.org)
编辑1
有什么问题或不可移植的约做这样的吗?:
history = urlresolvers.reverse('satchmo_order_history')
domain = Site.objects.get_current().domain
history_url = 'http://' + domain + history
foo = urlparse.urljoin('http://',format(domain))给出http:///mysite.org和urlparse.urljoin(foo,history),然后给出http:/// history /什么是我错过了吗?格式()又是什么,什么是{}? – handros
@ user1294974你不能使用'urlparse.urljoin'连接''http://''和你的域名,因为它们是部分URI碎片,并且不起作用。你必须连接两个字符串。我使用'str.format'('{}'是一个占位符),但它需要Python 2.7。如果它不起作用,你可以尝试用'http:// {0} .format(domain)'(Python 2.6)或''http://%s'%domain'或甚至'http: //'你好,你已经在做'域名'了。 –