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')

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

Popular posts from this blog

Django Form: MultipleChoiceField and How To Have Choices From Model Example

Jquery Validation fix for date format dd/mm/yyyy in Chrome and Safari

DJango Queryset comparing date time