0

I call a function in my template that returns sqlalchemy query result, (color value from the name of the tag). this is the query function :

def get_tag_color(name):
return db.session.query(Tag.tag_color).filter(Tag.tag_name == name).scalar()

and I call it in my template file:

 {% if server.tags  %}
  {% for tag in server.tags.split(",") %} 
   <strong><span style="background-color: {{ get_tag_color(tag) }};" class="label"> {{tag}}  </span></strong>
    {% endfor %}
     {% endif %}   

the problem is that I get just one result of the first tag. do you have any idea what I miss.

1 Answer 1

0

all these functions are working fine, the problem was that I have space between tags, and I solved it by removing space in each tag. this is the new function with strip() function :

 {% if server.tags  %}
 {% for tag in server.tags.split(",") %} 
 <strong><span style="background-color: {{ get_tag_color(tag.strip()) }};" class="label"> 
 {{tag}}  </span></strong>
 {% endfor %}
 {% endif %} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.