Categories
Python Answers

How to concatenate strings in Python Django templates?

Spread the love

To concatenate strings in Python Django templates, we can use the | operator.

For instance, we write

{% with "shop/"|add:shop_name|add:"/base.html" as template %}
{% include template %}
{% endwith %}

to use | and add to concatenate the shop_name variable between 'sho/' and '/base.html' in our template.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *