Django form values ​​without HTML escape

I need to set Django forms.ChoiceField to display currency symbols. Since django forms remove all HTML ASCII characters, I cannot get & # 36; ( & euro; ) or pound; ( & lb; ) to display the currency symbol.

<select id="id_currency" name="currency">
    <option value="&amp;#36;">&#36;</option>
    <option value="&amp;pound;">&pound;</option>
    <option value="&amp;euro;">&euro;</option>
</select>

Could you suggest any methods for displaying the actual HTML currency symbol, at least for part of the parameter value?

<select name="currency" id="id_currency">
    <option value="&amp;#36;">$</option>
    <option value="&amp;pound;">£</option>
    <option value="&amp;euro;"></option>
</select>

Update: Please note that I am using Django 0.96 since my application runs on Google App Engine.
And above <SELECT> is displayed using Django Forms.

currencies = (('&#36;', '&#36;'), 
              ('&pound;', '&pound;'), 
              ('&euro;', '&euro;'))    
currency = forms.ChoiceField(choices=currencies, required=False)

Thanks,
Arun.

+3
1

safe " mark_safe " , , Unicode HTML .

mark_safe

from django.utils.safestring import mark_safe

currencies = ((mark_safe('&#36;'), mark_safe('&#36;')), 
              (mark_safe('&pound;'), mark_safe('&pound;')), 
              (mark_safe('&euro;'), mark_safe('&euro;')))    

autoescape off

. {% autoescape off %} {% endautoescape %} .

Unicode

, . , , :

# coding=utf-8

:

currencies = (('$', '$'), 
              ('£', '£'), 
              ('€', '€')) 
+8

Source: https://habr.com/ru/post/1706901/


All Articles