社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

Python Flask:如何使用“{}”。多行字符串(“”)中的format(),尤其是html字符串?

Joerie Judong • 4 年前 • 1724 次点击  

您好目前我知道可以用{}格式化字符串变量。格式(x),但在多行字符串中(在本例中为“一个长html页面字符串”)执行此操作的具体程度如何?因为如果我将这些“{}.format()”放在像这样的多行字符串中,它肯定会以字符串的形式返回。

因为这就是问题所在,我只需要为电子邮件正文生成html_字符串,但是一些变量,比如下载链接,必须在这里输入。更不用说还有一个特殊的场景,取决于是否存在bool。


def generate_html_body(attachment_bool: bool,download_link: str):
    if attachment_bool is False:
        Letter_1 = "Helaas was deze te groot om via mail door te sturen."
        Letter_2 = "Klik hier om het bestand te downloaden."
    if attachment_bool is True:
        Letter_1 =  "U vindt het bestand terug in de bijlage."
        Letter_2 = "Is het bestand niet in de bijlage terug te vinden? Klik dan hier en download dan hier."



 html_string="""<html>
<head>
    <title>{{ title }}</title>
</head>



<body>
    <p>Uw GIPOD data is gereed,</p>
    <p> { Letter_1}</p>
    <a href="{}"> {{  Letter_2 }} </a>
    <p> U heeft 30 dagen de tijd om deze te downloaden. Bedankt om CLASSIFIED te gebruiken. </p>

    <table>
        <tr>
            <td>
                <p>
                    <![if !vml]><img width=500 height=500 src="" alt="logo" class="img-responsive"><![endif]>
                </p>
            </td>
        </tr>
        <tr>
            <td>
                <p></p>
            </td>
            <td>
            </td>
        </tr>
        <tr>
            <td>
                <p>
                    <span></span>
                </p>
            </td>
        </tr>
        <tr>
            <td>
                <p>
                    <span style='font-size:10.0pt;line-height:105%;font-family:Roboto;color:#00273F'>
                        classiefie<o:p></o:p>
                    </span>
                </p>
            </td>
        </tr>
        <tr>
            <td>
                <p>
                    <b>
                        <span>
                            <a href="classiefie"">
                                <span style='color:#0563C1'>classiefie"/span>
                            </a>
                        </span>
                    </b><span></span>
                </p>
            </td>
        </tr>
        <tr>
            <td>
                <p>
                    <span></span>
                </p>
            </td>
        </tr>
        <tr>
            <td>
                <p>
                    <b>
                        <span lang=NL style='font-size:7.0pt;line-height:105%;font-family:Roboto;
  color:#5EBA00;'>
                            Gelieve rekening te houden met het milieu
                            voordat u dit document afdrukt<o:p></o:p>
                        </span>
                    </b>
                </p>
            </td>
        </tr>
        <tr>
            <td>
                <p>
                    <span></span>
                </p>
            </td>
        </tr>
        <tr>
            <td>
                <p>
                    <span>
                        <![if !vml]><img img width=500 height=500 src="classiefie">
                    </span>
                </p>
            </td>
        </tr>
    </table>

</body>
</html>"""
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/129184
文章 [ 1 ]  |  最新文章 4 年前