Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Converts a block content into all uppercase

Tags:

django

Just starting to play around with Django and I'm trying to make the content of a block in all uppercase

my base.html template

{% block page-title %}{{ "test123"|upper }}{% endblock %}

and it will output perfectly with TEST123

I would like to make it always uppercase and not having to apply the upper tag each time I want to overwrite it.

For example in my contact.html

{% block page-title %}Contact us{% endblock %}

I want to keep it as DRY as possible and not having to type {{ "Contact us"|upper }} .

I've tried {{ {% block page-title %}{% endblock %}|upper }} but I get a TemplateSyntaxError

like image 853
Yannick Avatar asked Dec 18 '25 14:12

Yannick


2 Answers

You can use the {% filter %} tag to apply a filter to a whole bunch of variables.

{% filter upper %}
   A whole bunch of {{ text }} and {{ variables }}
{% endfilter %}
like image 132
Daniel Roseman Avatar answered Dec 21 '25 08:12

Daniel Roseman


While not addressing your question with Python there is a simple CSS approach (source):

text-transform: uppercase
like image 37
Jason Sperske Avatar answered Dec 21 '25 08:12

Jason Sperske



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!