Tom
Tom

Reputation: 22841

Django: Double-Escape XML Entities

Running into a bit of a corner case: the API I'm communicating with blows up when there's an ampersand or similar in the data, even though Django is escaping the data when rendering the XML template. The response I get from the API owner was:

As weird as it sounds, I think you need to double escape it. Try: &

Sensibly, Django doesn't really make this easy. Trying |escape|escape doesn't do what I want regardless of whether autoescape is on or off. I'm sure I can write a custom filter to do this, but I'm worried that will lead to other issues. Is there a simple way to do this with standard template filters?

Upvotes: 0

Views: 436

Answers (1)

Morgan Wahl
Morgan Wahl

Reputation: 26

The Django force_escape filter should work if applied twice.

Upvotes: 1

Related Questions