【问题标题】:bootstrap not working for django send_mail引导程序不适用于 django send_mail
【发布时间】:2020-06-24 07:48:56
【问题描述】:

在我的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)

在我的 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>

问题是在我的 GUI 中,引导代码工作正常,但是当我在邮件中发送内容时,引导功能没有应用

【问题讨论】:

    标签: python django bootstrap-4


    【解决方案1】:

    您应该将 css 代码放入您的模板中。因为大部分邮件客户端都会屏蔽多余的链接,避免恶意代码的执行。

    例如:

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

    【讨论】:

      【解决方案2】:

      您不能将引导类用于send_mail 函数,因为您需要引导CSSjs 用于引导classes,它只有在CSSjs 附加时才能正常工作模板。但是当你将它传递给 send_mail 时,邮件中没有 CSSjs 所以它不会在那里加载引导类。

      您只能使用简单的 Html 标签。

      如果你在send_mail template 中使用了cdn 的引导程序CSSjs,那么它可能会被应用。

      【讨论】:

        猜你喜欢
        • 2019-02-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-24
        相关资源
        最近更新 更多