Django Form: Adding html text to help_text in FormField or ModelField
Today I come across the requirement to have a link inside the help_text for ModelField. Hence I found this simple and fast solution and would like to share with you all.
Before:
my_field = models.CharField(max_length=10, help_text='Simple help text here')
Before:
my_field = models.CharField(max_length=10, help_text='Simple help text here')
Solution:
from django.utils.safestring import mark_safe
my_field = models.CharField(max_length=10, help_text=mark_safe('Simple help text here. <p>HTML code here</p>'))
That's it and your help text will have this html code in place.
Happy Coding!
Comments
Post a Comment