我想在變數中放置一個鏈接(在 View Django 中)但我得到一個錯誤。在 slug 部分(slug =% slug),Python% url與%u!
錯誤:%u 格式:需要一個數字,而不是 str
我使用 Folium 庫并想在彈出視窗中放置一個鏈接。所以,我不能使用普通模式,我必須使用另一種方法。
for i in range(10):
slug=i
url = Template(
"""
<!DOCTYPE html>
<html>
<body>
<a href="{% url 'test' slug= %slug %}" target="_blank" style=" text-align:
right; ">Mor Info</a>
</body>
</html>
"""%slug).render(Context({}))
popup = folium.features.GeoJsonPopup(
fields=["name"],
aliases=[f'{url}'],
labels=True,
localize=True,
style="background-color: yellow;")
uj5u.com熱心網友回復:
您已經傳遞了一個空背景關系,請使用它而不是字串格式。
for i in range(10):
slug=i
url = Template(
"""
<!DOCTYPE html>
<html>
<body>
<a href="{% url 'test' slug=slug %}" target="_blank" style=" text-align:
right; ">Mor Info</a>
</body>
</html>
""").render(Context({'slug': slug}))
popup = folium.features.GeoJsonPopup(
fields=["name"],
aliases=[f'{url}'],
labels=True,
localize=True,
style="background-color: yellow;")
或者只是寫%s,而不是%slug,我認為你把事情搞混了。
print("%s" % "1")
print("%(bla)s" % {'bla':1}) # close to what you're attempting.
foo=1
print("{bla}".format(bla=1))
print(f"{foo}")
全部列印'1'。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/480323.html
上一篇:如何讓我的布局框回應式包裝?
