Strativ Logo
en_US EN
en_US EN sv_SE SV

Django - 4 Steps With Mathfilter (smart free tips)

Facebook-f Linkedin-in Envelope Copy
  • by Strativ
  • 3MIN READ
  • 21 October 2021

Django

Django is a Python-based free and open source web framework that follows the architectural pattern model-template-views (MTV). It is maintained by the Django Software Foundation (DSF), an independent non-profit organization established in the United States.

The main goal is to facilitate the creation of complex, database-driven websites. The framework emphasizes reusability and "pluggability" of components, less code, low connectivity, rapid development and the principle of not repeating yourself. Python is used all the time, even for settings, files and data models. Django also offers an optional administrative interface for creating, reading, updating and deleting that is generated dynamically through introspection and configured via admin models.

A little history

Django was created in the fall of 2003, when web programmers at the magazine Lawrence Journal-World, Adrian Holovaty and Simon Willison, started using Python to build applications. Jacob Kaplan-Moss was hired early in the development shortly before Simon Willison's internship ended. It was released publicly under a BSD license in July 2005. The framework was named after guitarist Django Reinhardt. Adrian Holovaty is a Romanesque jazz guitarist and a big fan of him.

In June 2008, it was announced that a newly formed Django Software Foundation (DSF) would maintain the source code in the future.

Development tools with Django support

In order to develop a Django project does not require any special tools, as the source code can be edited with any conventional text editor. Nevertheless, editors specializing in computer programming can help increase productivity in development, e.g. with functions such as syntax selection. As it is written in Python, text editors who are aware of Python's syntax are beneficial in this regard.

Integrated Development Environments (IDEs) add additional features, such as troubleshooting, refactoring, and device testing. As with regular editors, Python-supported IDEs can be beneficial. In addition, some IDEs specializing in Python have integrated support for Django projects, so the use of such an IDE in developing such a project can further increase productivity.

4 stegsprocessen för Django mathfilters

Hi friends, I found an interesting knowledge to share with you regarding a feature in Django templates. I was able to run an MCQ program and found an arithmetic problem like in this application. I have asked 5 questions and for each question there are several choices. Among them, there is only one correct answer. So after participating in the test, you will be able to see a summary of the ongoing test field. For a better understanding, I provide the screenshots below.

8ZGTKn9tTlrZuDLfv

As I mentioned earlier there are 5 questions and I gave 4 correct answers and the last one was incorrect. So in the wrong column the number should be 1 which is 5 - 4 = 1. But it shows 5 which is the total number of questions. Immediately after, I thought about solving it in the front end. And searched for whether Django templates can do this or not and found an unregistered tag library called django-mathfilters. This library can perform certain arithmetic operations in the template such as - subtraction, addition, multiplication, division, absolute value, modulo, integer (floor) division.

I show you here how to use it, with my example above which is 5 - 4 = 1.


Step 1: First we need to install it with this command

– pip install django-mathfilter

e4U57QY29icXvevG847bgRIHPcTMX13xB2S5TxDXnaevULz4vD9lmeAfFLlVrUMfl3uJJ8fTgLpMBd7Xxmj

Step 2: In our project settings file we add this library in

   INSTALLED_APPS.

K 84BFG BkvzshIhHgrz9LZ0QkRoeIp1y2aGv8Uxl4J

Steg 3: We need to load the math filters at the top of our template which is one html -file.


Step 4: Now for subtraction we use the syntax ”object1.value | sub: object2.value”. For addition it will be "| add:" instead of "| sub:".

aMBgDueyCP i19YWVrmgQwfPtz7UMCY4BJcHSBWAlfH2TL 3l9jjRkuI4dYNH1o5G2S 9lo3cPjdoAYmsko12uHcvR30toZbtnEsn4qq1iTs9JGqtf5KctookZiOIq5mT m j6Yr=s1600

Now in the wrong column the number of wrong answers is 1 which is true. And the task is complete.

5KUuvi9FfJfArzw2Qht5c9KhVhTaOVRDIFSmZDwmFnUquH

That's all. I think it helps to save time sometimes. Hope to see you soon, tadaaa !!!


System development with Strativ

We at Strativ offer STRAtegic and innovaTIVe business relationships to our customers. Our mission is to equip our customers' businesses with digital solutions so that they become more competitive. You can read more about the projects we have done for our customers. You are also welcome to read more about tjservices we offer in the form of smart solutions, where Python and Django are used extensively in development.

Contact us for a free meeting!

Django
Book a free meeting with us

Let's develop!

Strativ Logo

Olof Palmes gata 29
111 22 Stockholm, Sweden 

+46 079-100 50 01
[email protected]
Navigate
  • Home
  • Contact
  • About Strativ
  • Careers
  • Smart Solutions
  • Blog
Menu
  • Home
  • Contact
  • About Strativ
  • Careers
  • Smart Solutions
  • Blog
Policy
  • Privacy Policy
  • General Terms and Conditions
  • Environmental policy
Menu
  • Privacy Policy
  • General Terms and Conditions
  • Environmental policy
Social
  • Linkedin
  • Facebook
Menu
  • Linkedin
  • Facebook
credit rating
BACK TO TOP
© Copyright 2021 Strativ. All rights reserved.
sv_SE SV
sv_SE SV
en_US EN
Menu
  • About us
    • About Strativ
    • Smart Team
  • Services
    • Smart Solutions
    • Smart Development
    • System Development
    • Concept & UI/UX
    • Smart Marketing
  • Customers
    • Our Customers
  • Careers
  • Blog
  • Contact

We use cookies to help us improve your experience on the site. For more details.

Privacy Policy
I understand