[英]'Template' object has no attribute 'replace'
每当我运行代码时,错误是这样的:
“模板”对象没有“替换”属性
你能帮忙的话,我会很高兴。 谢谢!
线
template = get_template("user/ticket_print.html")
返回一个Template
对象,而不是包含您放入模板的代码的string
(我认为您期望)。 并且Template
对象没有名为replace()
的方法导致您的错误。
要访问您可以使用的字符串
template.template.source
因此,我认为在您的情况下,您的观点稍有变化就可以解决问题:
def ticket_print(request, cartitem_id):
item = get_object_or_404(CartItem, object_id=cartitem_id)
template = get_template("user/ticket_print.html")
value = template.template.source
html_result = render_template(value, {"itest": item.cart,},)
return html_to_pdf(html_result, name=f"Ticket_Print{item}")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.