-2

If I do that:

var importance_not_matched = {{item.this_article_importance}} <= article_importance;

It seems to work but in my IDE (Pycharm) I have errors: "Expression expected" on the "<=" and "underterminated statment" on the final ";"

I'm using flask, item.this_article_importance is an int

I solved my issue by changing to:

year_not_matched = {{item.this_article_year <= article_year}};

I don't understand why it's better yet though

ThomaS
  • 815
  • 4
  • 13

2 Answers2

1

Depending on the type of value that is {{ item.this_article_importance }} you may have to use filter |safe, so that django does not escape it.

Something like this:

var importance_not_matched = {{ item.this_article_importance|safe }} <= article_importance;

You can verify that both variables really have the desired value, even the type, to ensure where the error comes from.

var this_article_importance = {{ item.this_article_importance|safe }};
console.log(typeof(this_article_importance), this_article_importance);

It's hard to know more without more information. You can review this question where the topic is discussed.

John
  • 770
  • 1
  • 9
  • 18
  • I think it wasn't that because I disabled autoescaping. But your answer will help me in the future I think – ThomaS Mar 05 '20 at 10:35
0

I solved my issue by changing to:

year_not_matched = {{item.this_article_year <= article_year}};

I don't understand why it's better yet though

ThomaS
  • 815
  • 4
  • 13