1👍
✅
Use the addslashes
built-in filter:
From the documentation’s example:
{{ value|addslashes }}
If value is "I'm using Django"
, the output will be "I\'m using Django"
.
0👍
You can write your own filter:
@register.filter
@defaultfilters.stringfilter
def replace(value, args=","):
try:
old, new = args.split(',')
return value.replace(old, new)
except ValueError:
return value
Then in your template:
{% load replace from mycustomtags %}
{{ account.company_name|escapejs|replace:"',\'" }}
(I haven’t tested)
- [Answer]-Django at extra_context 'unicode' object does not support item assignment
- [Answer]-Stop uwsgi when code updating
- [Answer]-Django – access variables in template
- [Answer]-Django don't serve static
- [Answer]-Django on a Mac
Source:stackexchange.com