사용자가 비밀번호를 성공적으로 업데이트했을 때 이메일 템플릿을 초안을 작성 중입니다.Django autoescape가 render_to_string (템플릿)에서 작동하지 않습니다?
나는 템플릿에서 {{autoescape off}}를 사용했으며 이는 render_to_string()을 사용하여 렌더링되었습니다.
그러나 이메일의 내용은 다음과 같이 직접 HTML의 꺾쇠 괄호를 보여줍니다
안녕 < 스팬 스타일 = '색상 : 블루'> 사용자! </span >
비밀번호가 성공적으로 업데이트되었습니다. 내가 Django2.0 내 코드를 사용하고
은 다음과 같습니다
{{ autoescape off}}
Hi <span style='color:blue'>user! </span>
Your password is updated successfully!
{{ endautoescape }}
인가
views.py
from django.core.mail import send_mail
from django.template.loader import render_to_string
def sendmail(request, title)
email_title = title
email_content = render_to_string('template.html',{'username':request.user.username})
recipient = request.user.email
send_mail(
email_title,
email_content,
'[email protected]',
[recipient,],
)
template.html 거기에 내 코드가 잘못 되었나요?
그렇지 않으면 render_to_string()을 사용하는 동안 autoescape가 항상 켜져 있습니까?
이 자동 이스케이프와 아무 상관이 없습니다. 이는 템플릿에서 템플릿에 삽입 된 HTML에 적용됩니다. –