In a Django template, is there a way to get a value from a key that has a space in it?
Eg, if I have a dict like:
{"Restaurant Name": Foo}
How can I reference that value in my template? Pseudo-syntax might be:
{{ entry['Restaurant Name'] }}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no clean way to do this with the built-in tags. Trying to do something like:
will throw a parse error.
You could do a for loop through the dictionary (but it’s ugly/inefficient):
A custom tag would probably be cleaner:
and use it in the template like so:
Or maybe try to restructure your dict to have “easier to work with” keys.