django


Django template custom tag as boolean


This seems such a simple thing but I can't seem to get it to work for one, and two I can't seem to be getting a straight forward answer online on wether it can or can't be done.
I just want a simple tag that will work like so
{% if my_tag %}
render something
{% else %}
render something else
{% endif %}
now I don't care about filters or any other ways you might be able to do the same thing, I want it to look exactly like that, and work like described, I have a simple tag made that actually does return True or False as needed, and it's called if I call the tag like this
{% my_tag %}
however it does't get called if I add an if in front of the tag, is a feature this simple and logical not implemented?
Like the link to the potential duplicate states, you can use an assignment tag similar to the following that will return the current time:
#register.assignment_tag
def get_current_time(format_string):
return datetime.datetime.now().strftime(format_string)
Within your template you can then do what you are desiring to do:
{% if get_current_time %}
...show time
{% else %}
...don't show time
{% endif %}

Related Links

Django CreateView field labels
403 CSRF errors when trying to login to Django Admin over an SSH tunnel
psycopg2 control connection IP address
Elasticsearch Sorting “breaks” filter
How to allow Tornado Web Server serve only local requests (from Django)?
DRF - serialize different models into one
Django + matplotlib : image is not refreshed after new figsave()
I contributed to cleanup the documentation. Rejected as invalid. I don't agree [duplicate]
“Post Image data using POSTMAN”
Adding a dict if the query set is empty
django rest framework https authentication - 403 forbidden
django admin truncate text in list_display
Heroku database table primary key doubled itself overnight
The way to write <a href=“”> on Django
Django makemigrations not detecting project/apps/myapp
Could anyone check if my relations between models are correct?

Categories

HOME
shell
uml
fabricjs
porting
localization
deep-learning
linkedin
string
redux-form
flex
apache-spark-mllib
r-googlesheets
simulink
pcl-crypto
distribution
openbugs
nancy
vuejs
wolframalpha
digital-signature
nim
asciidoctor-pdf
systemtime
react-toolbox
monit
maze
licensing
shared
oculus
intersystems-cache
wcag
spotipy
winexe
paperjs
glib
getpixel
lint
git-rewrite-history
bc
recurrent-neural-network
comparison-operators
stringtokenizer
dbnull
avcapturedevice
berkeley-db-je
gitlist
tf
context-sensitive-grammar
skin
quicktime
payload
rocks
pure-css
lrs
google-cloud-console
hclust
android-dateutils
gogs
vorpal.js
nservicebus5
kiosk
lz77
fuzzywuzzy
nullable
jnlua
opl
google-books
android-launcher
rrule
phpldapadmin
addressing-mode
sql-scripts
cuba
kissfft
ora-00904
winginx
qscrollarea
ecslidingviewcontroller
jammer
breakout
cnf
poker
insert-id
mantle
web-farm
josql
ilasm
floating-point-exceptions
urlrewriter
procedures
user-tracking
lr
rowlex
isapi-extension
tui
scrubyt
fault-tolerance
cardspace

Resources

Encrypt Message