How to concatenate variables into a Django template

Asked

Viewed 68 times

0

I have a Django magazine that receives data from a table to display the list on the screen, as below:

{% block content %}
    {% for item in itens_lista %}
        <div class="post">
            <h1><a href="">{{ item.DESCR_ITEM}}</a></h1>
        </div>
    {% endfor %}
{% endblock %}

For each item read a link is generated that opens the edit of the item, however, in addition to the description (item.DESCR_ITEM) of the item I would like to also display the code (item.COD_ITEM).

Today displays like this:

  • Cellular
  • Notebook
  • Flash drive

I’d like it to stay that way:

  • 001 - Cellular
  • 002 - Notebook
  • 003 - Pendrive

In advance I thank you for your help.

  • The code was not correct when I pasted it. Where {{ item appears.DESCR_ITEM}} is actually an html link whose label is this. I want this label to concatenate COD_ITEM + DESCR_ITEM

  • You tested my answer?

  • I just tested. It worked perfectly. Thank you so much for the tip.

  • I put the accepted. Thanks again.

  • Cool, It is interesting to always put the accepted when someone responds, so you and the author of the answer earn points. :-)

1 answer

0


Use the filter add:

{% block content %}
    {% for item in itens_lista %}
        <div class="post">
            <h1><a href="">{{item.COD_ITEM | add:" - " | add:item.DESCR_ITEM}}</a></h1>
        </div>
    {% endfor %}
{% endblock %}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.