【发布时间】:2015-01-23 18:07:05
【问题描述】:
使用 Django,我正在发送包含链接的 html 电子邮件,但我无法使链接正常工作。我试过在我的模板中使用{{request.get_full_path}},在我看来也使用request.build_absolute_uri()。任何帮助都会很棒!
在我的网站中,正确的 url 在这样的模板中给出,带有 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>
【问题讨论】:
-
您是否在模板上下文中设置了
request? / 为什么不使用full_url传递给模板? -
full_url 只生成域(
http://localhost:8000/),然后request.get_full_path获取其余部分(/software/select_citations/review_and_export/email_it/?csrfmiddlewaretoken=wHUsUMnlMiix&email_address=myEmail%40emailAddress.com)。但是,该网址最终与我从网站本身访问链接时得到的不同...... -
你有
django.core.context_processors.request -
是的,
django.core.context_processors.request在我的设置文件中...
标签: django django-templates django-urls