Consider the following structure:
models.py:
class modela(models.Model):
fielda = models.BooleanField(default=True, choices=((True, 'some <b>bold</b> text'), (False, 'zzz')))
forms.py:
class forma(forms.ModelForm):
class Meta:
model = modela
widgets = {'fielda': forms.RadioSelect}
fields = '__all__'
views.py:
def a(request):
form = forma()
return render(request, 'a.html', {'form': form})
a.html:
{{ form.fielda }}
Django kindly escapes the tags for me as
How do I render it as HTML tags like
{{ form.fielda | safe }} doesn’t work, either.
>Solution :
Use the django.utils.safestring.mark_safe method to mark the string as safe for outputting in your template
from django.utils.safestring import mark_safe
class modela(models.Model):
fielda = models.BooleanField(default=True, choices=((True, mark_safe('some <b>bold</b> text')), (False, 'zzz')))

