bootstrap 4 css is not working with mail html template in flask

耗尽温柔 提交于 2021-02-11 14:48:09

问题


so i have this html template that i am using as mail template to send my users for reset their password's. i want to use bootstrap 4 classes in the template but it's not working. How do i make this work ? I've tried inline css and it works fine but i want to use bootstrap 4 css. Any help would be appreciated.

HTML template

<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{title}}</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Poppins&family=Rubik:wght@300&display=swap" rel="stylesheet">
</head>

<body>


    <div class="container">
        <div class="text-center">
            <h2>Have you just requested for the password reset !</h2>
            <a href="#" class="btn btn-outline-success">Reset Password</a>
        </div>
    </div>

    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" charset="utf-8"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.bundle.min.js" charset="utf-8"></script>
</body>

</html>

Flask Code

@app.route('/forget', methods=['GET', 'POST'])
def forget_password():
    form = ForgetPassword()
    if request.method == 'GET':
        return render_template("forget.html", title="Forget Password", form=form)
    email = request.form['email']
    session['email'] = email
    token = s.dumps(email, salt='reset-password')
    msg = Message("Password Reset", sender="bookverm1999@gmail.com", recipients=[email])
    link = url_for("reset_pass", token=token, _external=True)
    msg.body = "Password Reset Link"
    msg.html = render_template("mail.html", link=link, title="Password Reset")
    mail.send(msg)
    return render_template("sent.html", title="Email Sent")


回答1:


You can only use inline css, email doesen't support css linking, it is only supported by browsers. I already tried to do that with an old css i created some time ago but i had to embed it in the html.



来源:https://stackoverflow.com/questions/61500245/bootstrap-4-css-is-not-working-with-mail-html-template-in-flask

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!