Jurudocs
Jurudocs

Reputation: 9175

How to tell Django not to escape html from request.POST data?

Im using ajax to get svg graphs and django escapes all html signs...how can i prevent this and get the raw data?

Thanks a lot!

Upvotes: 0

Views: 824

Answers (2)

tonino.j
tonino.j

Reputation: 3871

If your view is outputting your svg, it escapes it if you serve it as a string. But svg equals xml which means that you could serve your svg using django templating.

Upvotes: 2

spencer nelson
spencer nelson

Reputation: 4535

If you mean that django escapes the HTML on its way out in the response, then it's simple - wrap any HTML strings in mark_safe (from from django.utils.safestring import mark_safe)

Like this:

def myview(request):
    html_data = "<h1>Hello world!</h1>"
    return render(request, "template.html", {"html": mark_safe(html_data)})

Upvotes: 0

Related Questions