I have a need for an If/Else statement in my Django (3.1.5) template check if a value exists in a dictionary (very popular concept). My challenge here is now trying to use the value from the dictionary it matched on.
I know i can use a for loop and then use another if to match again when that value exists but i am wondering if there is a shorter way to do what i am looking for.
For example, in my template i have 2 query sets, config
and user_settings
that i pass to the template. What i do is check if the name from the config
exists in the user_setting
dictionary, then I use the config
details in a form. What I want to do is take the "total" field from user_settings
dictionary that matched on the if in statement. In the below code the, the piece i am talking about is on line 6 value=''
. This clearly doesn't work but can i do something like that to reduce the amount of code?
https://stackoverflow.com/questions/67378270/use-dictionary-value-from-if-in-statement May 04, 2021 at 11:04AM
没有评论:
发表评论