Django Form values without HTML escape

天涯浪子 提交于 2019-12-05 12:54:16
Sergey Golovchenko

You can use "safe" in the template or "mark_safe" in the view, turn off autoescaping in the template, or use Unicode characters instead of HTML entities in your form.

Using mark_safe

from django.utils.safestring import mark_safe

currencies = ((mark_safe('$'), mark_safe('$')), 
              (mark_safe('£'), mark_safe('£')), 
              (mark_safe('€'), mark_safe('€')))    

Using autoescape off

As an alternative in your template you can turn off escaping for a block of code. Everything between tags {% autoescape off %} and {% endautoescape %} will not be escaped.

Using Unicode characters

When nothing else works try the following. In the file that contains your currencies tuple put the following line as the very first or second line:

# coding=utf-8

and then in your currencies tuple put the actual unicode characters:

currencies = (('$', '$'), 
              ('£', '£'), 
              ('€', '€')) 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!