原始HTML代码视图,返回Python中的函数
我需要返回函数notification\u视图以显示html代码。 我使用Response,但它将结果作为模板返回,而不是以html代码返回原始HTML代码视图,返回Python中的函数,python,python-3.x,flask,response,Python,Python 3.x,Flask,Response,我需要返回函数notification\u视图以显示html代码。 我使用Response,但它将结果作为模板返回,而不是以html代码返回 from flask import Response def notification_view(user_id, notification_id): """ View notification of user """ notification = Notification.query.filter(Notificati
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函数在类notification中的render方法中传输信息
我明白了:
但我需要但我需要显示的信息的html代码
html样式=填充:0;保证金:0 >应用程序密码恢复登录到仪表板< P>亲爱的李约翰, < P>已要求密码重置此帐户。访问此链接并输入新密码 如果您没有请求密码重置,请忽略并删除此电子邮件。请注意:请求将在24小时后过期。问候,应用程序支持我将html更改为纯mimetype格式
作为模板而不是html代码意味着什么?你到底看到了什么?你到底有什么问题?你尝试了什么没有用?@DanielRoseman我已经更新了我仍然不明白的问题。如果您需要原始HTML,您可以在浏览器中使用view source,否?否,我需要未在浏览器中使用view source的原始HTML
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)
return Response(notification.render('mail'),mimetype='text/plain')