我需要返回函數notification_view
顯示html代碼。 我使用Response
,但它將結果作爲模板返回,但不以html代碼形式返回。查看原始HTML代碼,它返回Flask中的函數Python
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
功能發送在render
方法,該方法在一個class Notifikation
信息。
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 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>
「作爲模板,而不是HTML代碼」是什麼意思?你究竟看到了什麼? –
究竟是什麼問題?你做了什麼沒有奏效? –
@DanielRoseman我已更新問題 – Mark