查看原始 HTML 代码,其中 returns Flask Python 中的函数

view of raw HTML code, which returns the function in Flask Python

我需要 return 函数 notification_view 显示 html 代码。 我使用 Response,但它 return 将结果作为模板,但不在 html 代码中。

from flask import Response 

def notification_view(user_id, notification_id):
        """ View notification of user """
        notification = Notification.query.filter(Notification.unique_id == notification_id,
                                                 Notification.user_id == user_id).first_or_404()

        return Response(notification.render('mail'), mimetype='text/html')

notification_view 函数在 class Notifikation.

中的 render 方法中传输信息
class Notification(db.Model):
    unique_id = db.Column(db.String(255), primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey("user.id")
    type = db.Column(db.String(60))


    def render(self, purpose):
        notification_meta = NOTIFICATIONS.get(self.type)
        if purpose == "mail" and "mail" in notification_meta:
            return render_template(notification_meta["mail"], **render_data)

我明白了:

但是我需要但是我需要显示html消息的代码

html style="padding: 0; margin: 0"> <body style="padding: 0; margin: 0"> <table width="100%" border="0" style="border-collapse: collapse; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"> <tr> <td align="left" width="50%" valign="middle" style="background-color: #3c8dbc; height: 40px; color: white; padding-left: 10px;"> <span style="font-size:20px;">App</span> <span style="font-size:16px;"> Password Recovery</span> </td> <td align="right" width="50%" valign="middle" style="background-color: #3c8dbc; height: 40px; font-size:14px; padding-right: 10px;"><a style="color: white;" >Login to dashboard</a></td> </tr> <tr> <td colspan="2" style="padding: 10px; font-size: 16px;"> <p>Dear John Lee,</p> <p>A password reset has been requested for this account. <a h>Visit this link</a> and enter your new password. </p> <p>If you did not request a password reset, please ignore and delete this e-mail.</p> <p>Please note: The request will expire in 24 hours.</p> </td> </tr> <tr> <td colspan="2" style="padding: 10px; font-size: 16px; font-style: italic; color: #3c8dbc; "> Kind regards,<br> App Support </td> </tr> </table> </body> </html>

我在mimetype

中将html改为plain
 return Response(notification.render('mail'),mimetype='text/plain')