RISOLTO Concatenare una str e un int nel template di python django framework

Pubblicità

BigIssue

Utente Attivo
Messaggi
226
Reazioni
18
Punteggio
45
Buongiorno a tutti,
non riesco a trovare una risposta. Forse mi potete aiutare voi.

Python:
<form id="formDoc" style="margin-top: 10px;" action="/" method="post">
        {% for keyFi,valueFi in tmplVar.jsonKeysDocFields.items %}
           
        {% with field_index="field_"|add:keyFi|stringformat:"s" %}
   
            <div style="margin-bottom: 5px; display: none;" id="{{field_index}}" class="docFieldWrapper">

Non riesco a capire perchè field_index è vuota cioè id="". Dovrebbe stampare qualcosa come field_version_ oppure field_controparte_
Dove sbaglio?
 
Ho provato anche a costruire un tag custom

file pyconcat_tags.py
Python:
from django import template
register = template.Library()
@register.filter
def concat_string(value_1, value_2):
    return str(value_1) + str(value_2)

file home.html
HTML:
{% load pyconcat_tags %}
    <form id="formDoc" style="margin-top: 10px;" action="process2_module_doc.php" method="post">
        {% for keyFi,valueFi in tmplVar.jsonKeysDocFields.items %}
            
        {% with field_index=concat_string "ciao" "come" %}
        <div style="margin-bottom: 5px; display: none;" id="{{field_index}}" class="docFieldWrapper">

L'erorre che ricevo è questo: TamplateSyntaxError
'with' received an invalid token: '"ciao"'

Bho, la with è una parola riservata e serve per definire variabili dentro il template. la stringa "ciao" è un parametro per la funzione concat_string cosi anche "come".
 
Pubblicità
Pubblicità
Indietro
Top