Reputation: 6753
I have a Django template that looks like this:
<div id="objects">
<b>Ingredients:</b>
<small>
{% for obj in result.object.list_objects|slice:":10" %}
.{{ obj }}
{% endfor %}
......
</small>
</div>
I am trying to output a simple list but when I loop through these elements in the template, the output is unfortunately in single quotes for each object. I am new to Django templates and have tried using a few methods like safe
and escape
. But the single quotes remain. Is there a way in Django to strip out that specific character when loading the data?
Upvotes: 3
Views: 3868
Reputation: 31
You can use
{% for obj in result.object.list_objects %}
{{ obj|slice:"1:-1" }}
{% endfor %}
Upvotes: 3
Reputation: 101
This question looks a bit dated, but wanted to toss in a simple solution. You can make a custom template tag and use the replace function.
Example:
@register.filter
def strip_double_quotes(quoted_string):
return quoted_string.replace('"', '')
{{ my_quoted_string|strip_double_quotes }}
Upvotes: 6