How to do math in a Django template

0 votes

I want to do this:

100 - {{ object.article.rating_score }} 

So for example, the output would be 20 if {{ object.article.rating_score }} equaled 80.

How do I do this at the template level? I don't have access to the Python code.

Jun 23, 2020 in Python by kartik
• 37,530 points
2,070 views

1 answer to this question.

0 votes

Hello @kartik,

You can use the add filter:

{{ object.article.rating_score|add:"-100" }}

Thank You!!

answered Jun 23, 2020 by Niroj
• 82,820 points

Related Questions In Python

0 votes
1 answer

How to do a not equal in Django queryset filtering?

Hello @kartik, Your query appears to have a ...READ MORE

answered Jun 26, 2020 in Python by Niroj
• 82,820 points
8,951 views
+1 vote
1 answer

How do I return JSON without using a template in Django?

Hello @kartik, In the case of the JSON ...READ MORE

answered Jul 3, 2020 in Python by Niroj
• 82,820 points
2,954 views
0 votes
1 answer

How to access a dictionary element in a Django template?

Hello @kartik, Use Dictionary Items: {% for key, value ...READ MORE

answered Jul 3, 2020 in Python by Niroj
• 82,820 points
7,760 views
0 votes
1 answer

How to access the user profile in a Django template?

Hello @kartik, In your profile model provide related_name user ...READ MORE

answered Jul 29, 2020 in Python by Niroj
• 82,820 points
2,004 views
0 votes
1 answer

How to temporarily disable a foreign key constraint in MySQL?

Hello @kartik, To turn off foreign key constraint ...READ MORE

answered Jun 23, 2020 in Python by Niroj
• 82,820 points
926 views
0 votes
1 answer

How do I use Django templates without the rest of Django?

Hello @kartik, Let's say you have this important ...READ MORE

answered Jun 23, 2020 in Python by Niroj
• 82,820 points
418 views
0 votes
1 answer

How to call function that takes an argument in a Django template?

Hello @kartik, You cannot call a function that ...READ MORE

answered Jun 23, 2020 in Python by Niroj
• 82,820 points
5,597 views
0 votes
1 answer

How to output text from database with line breaks in a django template?

Hello @kartik, Use linebreaks or linebreaksbr filter: {{ text|linebreaks }} Or surround the text ...READ MORE

answered Jun 24, 2020 in Python by Niroj
• 82,820 points
4,224 views