How can I turn off Django's automatic HTML escaping, when I write into model's TextField?
+1
A:
One way to do it is to put a function in your model which returns the data marked as safe:
from django.utils.safestring import mark_safe
class MyModel(models.Model):
myTextField = models.TextField()
def display_mySafeField(self):
return mark_safe(self.myTextField)
Then in the template you would have to use:
{{instance.display_mySafeField}}
Daniel Vassallo
2010-01-17 09:43:21
That's, exactly what I needed :) Thank you very much.
Shark
2010-01-17 09:59:08
If you use django's safe filter you do not need to modify the model at all.
bjunix
2010-02-15 17:55:20