Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 3在向邮件发送信函时,信函中的图像不显示,如何修复? subject=name\u电影院 html\u message=render\u to\u string('app\u template/mail\u template.html',上下文) 普通消息=带标签(html消息) from_email='from' 收件人=电子邮件 mail.send_mail(主题,普通邮件,from_email,[to],html_message=html_message)_Django - Fatal编程技术网

Django 3在向邮件发送信函时,信函中的图像不显示,如何修复? subject=name\u电影院 html\u message=render\u to\u string('app\u template/mail\u template.html',上下文) 普通消息=带标签(html消息) from_email='from' 收件人=电子邮件 mail.send_mail(主题,普通邮件,from_email,[to],html_message=html_message)

Django 3在向邮件发送信函时,信函中的图像不显示,如何修复? subject=name\u电影院 html\u message=render\u to\u string('app\u template/mail\u template.html',上下文) 普通消息=带标签(html消息) from_email='from' 收件人=电子邮件 mail.send_mail(主题,普通邮件,from_email,[to],html_message=html_message),django,Django,布局mail_template.html,问题是iz来自图像,iz来自内容的所有规范 图中显示了不到4个变量,取消了对图像的调用。{%load static%}连接 subject = name_cinema html_message = render_to_string('app_template/mail_template.html', context) plain_message = strip_tags(html_message) from_email = 'From <examp

布局mail_template.html,问题是iz来自图像,iz来自内容的所有规范 图中显示了不到4个变量,取消了对图像的调用。{%load static%}连接

subject = name_cinema
html_message = render_to_string('app_template/mail_template.html', context)
plain_message = strip_tags(html_message)
from_email = 'From <example12090@gmail.com>'
to = email

mail.send_mail(subject, plain_message, from_email, [to], html_message=html_message)

4.

这不起作用的原因是
{%static'img/1234.png%%}
将解析为
/static/img/1234.png
或类似的内容。但是没有主机名或协议,因此电子邮件客户端不知道从哪里获取这些图像

您可以通过以下方式传递站点名称,例如:

<img src="{% static 'img/1234.png' %}" alt="1">
<img src="{% static 'img/1.png' %}" alt="2">
<img src="../../1234.png" alt="3">  

4<img src="https://www.meme-arsenal.com/memes/579eb482a8540ee55b0bf3db8695a783.jpg" alt="4">
从django.contrib.sites.shortcuts导入获取当前站点
站点名称=获取当前站点(请求)。名称
html\u message=将\u呈现为\u字符串(
“app_template/mail_template.html”,
{'site\u name':site\u name,**context}
)
在模板中,可以使用以下工具渲染这些对象:

from django.contrib.sites.shortcuts import get_current_site

site_name = get_current_site(request).name
html_message = render_to_string(
    'app_template/mail_template.html',
    {'site_name': site_name, **context}
)
{{site\u name}{%static'img/1234.png%%}alt=“1”>

{{site_name}{%static'img/1.png%%}alt=“2”>这不起作用的原因是
{%static'img/1234.png%%}
将解析为
/static/img/1234.png
或类似的内容。但是没有主机名或协议,因此电子邮件客户端不知道从哪里获取这些图像

您可以通过以下方式传递站点名称,例如:

<img src="{% static 'img/1234.png' %}" alt="1">
<img src="{% static 'img/1.png' %}" alt="2">
<img src="../../1234.png" alt="3">  

4<img src="https://www.meme-arsenal.com/memes/579eb482a8540ee55b0bf3db8695a783.jpg" alt="4">
从django.contrib.sites.shortcuts导入获取当前站点
站点名称=获取当前站点(请求)。名称
html\u message=将\u呈现为\u字符串(
“app_template/mail_template.html”,
{'site\u name':site\u name,**context}
)
在模板中,可以使用以下工具渲染这些对象:

from django.contrib.sites.shortcuts import get_current_site

site_name = get_current_site(request).name
html_message = render_to_string(
    'app_template/mail_template.html',
    {'site_name': site_name, **context}
)
{{site\u name}{%static'img/1234.png%%}alt=“1”>

{site_name}{%static'img/1.png%%}alt=“2”>
static在您的电子邮件中不起作用,因为这会导致
/static/img/1234.png
,但它需要前面的协议和主机。static在您的电子邮件中不起作用,因为这会导致
/static/img/1234.png
,但它需要协议和主机在前面。这是非常有用的发现,但我仍然无法修复错误,我在本地服务器上,如何修复它?或者是否需要在主机上部署项目?@alter_table:如果它在本地运行,您可能还应该指定端口(例如so
:8000
),并检查电子邮件客户端是否允许这样做。您可能希望检查已发送的电子邮件中的“源代码”。这非常有用,但我仍然无法修复错误,我在本地服务器上,如何修复它?或者是否需要在主机上部署项目?@alter_table:如果它在本地运行,您可能还应该指定端口(例如so
:8000
),并检查电子邮件客户端是否允许这样做。您可能希望检查已发送电子邮件中的“源代码”。