Reputation: 29
I am trying to pass the name of "Angela's Ashes" in a single bracket like below.
href="{{ url_for('cart', name = 'Angela's Ashes')}}"
Is there anyway to type in this without creating another variable?
Upvotes: 0
Views: 91
Reputation: 179432
If this is a HTML template, you can try using double-quotes inside the {{ }}
- since those are within the template argument, only the template engine will see the quotes and it won't affect the HTML:
<a href="{{ url_for("cart", name = "Angela's Ashes") }}">
Upvotes: 1
Reputation: 18796
You're looking for html.escape(s, quote=True)
, or simply replace
'
with '
where you need it
>>> import html
>>> html.escape("Angela's Ashes")
'Angela's Ashes'
Other XHMTL escapes can be seen here https://en.wikipedia.org/wiki/Numeric_character_reference#Examples
(you can also do this for any character, not only special ones, but it will lead to a longer and more confusing document)
>>> html.unescape("a")
'a'
Upvotes: 0