я создаю HTML для электронной почты, используя строку Python, например, так:Python ValueError: слишком много значений для распаковки со строкой форматирования
# Code setting up the message html
message = "long html message string"
scoped = ""
if settings.DEBUG:
scoped = "scoped"
header = """
<style %s type='text/css'>
@media only screen and (max-width: 480px){
.emailImage{
height:auto !important;
max-width:200px !important;
width: 100% !important;
}
}
</style>
""" % scoped
footer = "html message footer"
message = header + message + footer
# Code sending the message.
Проблема заключается в том, выше код дает мне ошибку ValueError: too many values to unpack
. Однако, если я удаляю переменную scoped
из сообщения, выполняется html, т. Е. Это работает (хотя и без добавления переменной области видимости в мой HTML, как я ее хочу).
# Code setting up the message html
message = "long html message string"
header = """
<style type='text/css'>
@media only screen and (max-width: 480px){
.emailImage{
height:auto !important;
max-width:200px !important;
width: 100% !important;
}
}
</style>
"""
footer = "html message footer"
message = header + message + footer
# Code sending the message.
Почему первая версия бросает эту ошибку и как я могу обратиться к ValueError?
Почему вы создаете HTML путем замены строки? Для этого нужны шаблоны. –