简体   繁体   English

引导程序不适用于 django send_mail

[英]bootstrap not working for django send_mail

In my views.py I have the following code在我的 views.py 我有以下代码

def cpio(request):
    mainDict9=['hemant','jay','yash','Hari']
    args={'mainDict9':mainDict9,}

    msg_html =render_to_string('/home/user/infracom2/JournalContent/templates/JournalContent/test1.html', 
    {'mainDict9':mainDict9,})

   from_email = 'gorantl.chowdary@ak-enterprise.com'
   to_email = ['gorantla.chowdary@ak-enterprise.com']
   subject="TESTING MAIL"   
   send_mail('email title',subject,from_email,to_email,html_message=msg_html,)

return render(request,'JournalContent/test1.html',args)

In my test1.html I have my following code在我的 test1.html 中,我有以下代码

<!DOCTYPE html>
    <html>
        <table class="table table-bordered">
        <thead>
            <tr>
                <th scope="col" class="table-secondary"><center>Modified Binaries/components</center></th>
                <th scope="col" class="table-secondary"><center>CRs</center></th>
           </tr>
        </thead>
        <tbody>
            {% for king in mainDict9 %}
            <tr>
                <td style="width: 10px;" class="table-active">{{ king }}</td>
                <td style="width: 10px;" class="table-active"></td>         
           </tr>
           {% endfor %}
       </tbody>
  </table>
</html>

The problem is in my GUI the bootstrap code is working fine but when I send the content in mail bootstrap functions are not applying问题出在我的 GUI 中,引导程序代码工作正常,但是当我在邮件引导程序功能中发送内容时不适用

You should to put css code inside your template.您应该将 css 代码放在模板中。 Because most email client will block extra link to avoid execution of malicious code.因为大多数电子邮件客户端会阻止额外的链接以避免执行恶意代码。

For example:例如:

 <style>
  body {background-color: powderblue;}
  h1 {color: red;}
  p {color: blue;}
</style> 

You can not use bootstrap class for send_mail function because you need bootstrap CSS and js for the bootstrap classes it will work fine only and only when that CSS and js are attached with the template.您不能将 bootstrap 类用于send_mail函数,因为您需要 bootstrap CSSjs作为 bootstrap classes它只有在CSSjs与模板附加时才能正常工作。 But when you pass it into send_mail there were no CSS and js in the mail so it will not load the bootstrap classes over there.但是当您将它传递给 send_mail 时,邮件中没有CSSjs ,因此它不会在那里加载引导程序类。

You can only use a simple Html tag.您只能使用简单的 Html 标记。

And other things might be if you used cdn of bootstrap CSS and js in send_mail template then might be it will be applied.其他事情可能是,如果您在send_mail template使用了 bootstrap CSSjs cdn ,那么它可能会被应用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM