Вокруг поплавка до int в jinja2

Неверный пример:

import  sun.audio.*;    //import the sun.audio package
import  java.io.*;

//** add this into your application code as appropriate
// Open an input stream  to the audio file.
InputStream in = new FileInputStream(Filename);

// Create an AudioStream object from the input stream.
AudioStream as = new AudioStream(in);         

// Use the static class member "player" from class AudioPlayer to play
// clip.
AudioPlayer.player.start(as);            

// Similarly, to stop the audio.
AudioPlayer.player.stop(as); 
0
задан larsks 2 March 2019 в 03:41
поделиться

1 ответ

Вы используете Jinja, но вы ссылаетесь на документацию по функциям Python. Jinja! = Python: вам нужно использовать filters или методы объекта при работе с выражениями Jinja. Так, например, вы можете использовать фильтр int :

{% if book.average_score %}
  {% for s in range(book.average_score|int) %}
     <i class="fas fa-star"></i>
  {% endfor %}
{% endif %}

Или круглый фильтр:

{% if book.average_score %}
  {% for s in range(book.average_score|round) %}
     <i class="fas fa-star"></i>
  {% endfor %}
{% endif %}

Вы можете контролировать поведение фильтра round с параметром mode, который может быть либо common (по умолчанию), floor или ceil:

{% if book.average_score %}
  {% for s in range(book.average_score|round(mode='ceil')) %}
     <i class="fas fa-star"></i>
  {% endfor %}
{% endif %}
0
ответ дан larsks 2 March 2019 в 03:41
поделиться
Другие вопросы по тегам:

Похожие вопросы: