Django view returns string which is not represented correctly in html template -
One view gives a string for the html template I, the string returned is special characters that are properly in the template Do not represent. To keep it only a string that comes back from the scene, it may look like this:
test = "\" Foo bar \ "" render_to_response ('index.html', { 'Test': Test}) and is displayed in the html template like this:
& amp; Quot; Foo Bar & amp; Quot; How can I fix the encoding so that it appears properly?
When printing use:
{{test | Safe}} Or, in this view:
django.utils.safestring import mark_safe test = mark_safe ("\" Foo bar \ "" ) Please note that by doing this, you are telling Django that the string is safe and there is no need to avoid HTML. If you are planning to do anything to the user, it will leave you unsafe for XSS attacks, so use it carefully.
Comments
Post a Comment