python - 如何在 Jinja 2 模板中传递转义字符串变量
问题描述
这是一个简单的任务,我想将颜色例如:“rgb(255,255,0)”传递给 html 文件,以便可以更改文本颜色。
我在 html 文件中使用了这个片段
``{% for i in range(0,len) %}
new mapboxgl.Marker({
color: {{ colors[i]|safe }}
}).setLngLat([
{{ lang[i] }},
{{ lat[i] }}])
.addTo(map);
{%endfor%}
我通过以下方式传递颜色列表:
colors=[]
maxValue = max(totalConfimedList)
for item in totalConfimedList:
print(item)
# colors.append(code_map(int(item),0,int(maxValue),0,255))
if int(item) >255:
colors.append("\'rgb(255,0,0)")
continue
colors.append("\"rgb("+item+"0,0)\"")
在 HTML IN CHROME 中,它即将到来,因为color: "rgb(200,0)"
颜色未到来。请帮我
解决方案
colors = []
totalConfimedList = ['123', '255', '256', '375', '367']
maxValue = max(totalConfimedList)
for item in totalConfimedList:
print(item)
# colors.append(code_map(int(item),0,int(maxValue),0,255))
if int(item) > 255:
colors.append('rgb(255,0,0)')
continue
colors.append('rgb('+item+',0,0)')
神社 2 模板:-
{% for i in colors %}
color: [{{ i|safe }}]
{%endfor%}
推荐阅读
- javascript - I2C + cron 无法在 Raspberry Pi 中运行
- pine-script - 不同时间范围的 Pinescript ATR
- sql - 如何从不同 ip 中的另一个 SQL Server 插入数据字段表 SQL Server?
- sql - 使用动态 SQL 仅选择满足的条件
- c# - Azure Ad SSO 成功收到 IdToken 但 Request.IsAuthenticated 为 false 并在 asp.net MVC 5 中声明为 null
- django - 如何在没有模型的情况下上传到 S3 之前更改 django InMemoryUploadedFile 的文件名?
- entity-framework - Chinook 数据库-LINQ。我有一个播放列表,我需要写下她的名字、歌曲数量和她的主要流派(该播放列表中的歌曲最多。)
- flow-project - 如何定义流网络中的车道宽度?
- angular - 如何禁用从 URL 的直接访问
- cpu-architecture - 为什么一条指令需要多个时钟周期才能执行