Pu Yang
Pu Yang

Reputation: 29

How can I type 's in python

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

Answers (2)

nneonneo
nneonneo

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

ti7
ti7

Reputation: 18796

You're looking for html.escape(s, quote=True), or simply replace ' with &#x27; where you need it

>>> import html
>>> html.escape("Angela's Ashes")
'Angela&#x27;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("&#x61;")
'a'

Upvotes: 0

Related Questions