使用Django的html电子邮件中的绝对URL

时间:2014-11-25 16:23:53

标签: django django-templates django-urls

使用Django,我发送的是包含链接的html电子邮件,但我无法获取链接。我尝试在我的模板中使用{{request.get_full_path}},并在我的视图中使用request.build_absolute_uri()。任何帮助都会很棒!

在我的网站中,模板中提供了正确的网址,其中包含url =" / review_and_export /":

<a href="{url}{{request.get_full_path}}{{ publication.pk }}/?bibtex" target="_blank">BibTex</a>

目前,这是我的电子邮件地址:

views.py

# for links in html email??
full_url = request.build_absolute_uri()
full_url = full_url.split("/software/", 1)[0]   #this produces just the domain, EDIT: i was missing a slash...still having issues

html_content = render_to_string(email_it, {'full_url' : full_url,....}, context_instance=RequestContext(request))

email_it.html

{% for publication in value %}
    {% include "software/display_citations.html" with publication=publication url=full_url%}
{% endfor %}

display_citations.html

# I use full_url and request.get_full_path because get_full_path doesn't return the domain
<a href="{{full_url}}{{request.get_full_path}}{{ publication.pk }}/?bibtex" target="_blank">BibTex</a>

1 个答案:

答案 0 :(得分:0)

我通过在视图中进一步操作url然后将该结果与我模板中的参数连接来解决这个问题。谢谢你的帮助!