python - Making text bold with django -


i have send make text bold in between plain text , send template view. this:

i save string <b>textplaintext</b> in variable , return template. "<b>" tags not interpreted.

how can make text bold in django view?

making text bold shouldn't done in view. indeed, view should not take care of formatting (which role of templates). can however, adding variable rendering context, , depending on value, make text bold or not in template.

for example :

in view :

#... is_important = true if else false extra_context.update({'is_important': is_important}) #... 

in template :

... {% if is_important %}<bold>{{ text_to_render }}</bold>{% else %}{{ text_to_render }}{% endif %} ... 

but more generally, deciding if text bold or not, not formatting, rather styling , should not made in template (so shouldn't use <bold> markup). suggest :

... <span {% if is_important %}class="is-important"{% endif %}> {{ text_to_render }} </span> ... 

and stylesheet :

.is-important{     font-weight: bold; } 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -