About Ternary Operators
Python ternary operators not only don't return the value under false conditions but also don't execute it, for example, division by zero will be ignored in the following snippet, because the condition is falsey:
1 2 |
|
You can safely use this fact for Django cases like this:
1 |
|
Tips and Tricks Programming Django 4.2 Django 3.2 Django 2.2 Python 3
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django GDPR Cookie Consent app
For Django websites that use cookies.