Python – Displaying dictionary value in django template



I have the following in my

def getgradeform(request):
   dict.update({'sc': sc})
   return render_to_response('content/add.html',dict)

Logging.debug gives an output as [<sc: Robert>]

My question is that how do i display Robert in the template .

I have tried the following in the template:<input type ="text" value={{sc}}/> //This gives me the dictionary itself

<input type ="text" value={{}}/> //This also doesnt work.


Best Solution

If you want any value in a dictionary, you have to do it on the way


(On python you'll write it as dict['key'])

So, to present the value stored with key 'name'

{{ }}

Anyway, I think this is not you're case. I think you're not seeing a dictionary, but an object defined from models (as is a entry on the database). You're storing in dict (don't call that value as dict , you're masking a keyword) a key 'sc' with value variable sc, which is returned from a model. I'm having to guess, because I don't know how this model is. Maybe 'Robert' is stored in the attribute name, id or something similar?

You need to show then the proper attribute, something like

{{ }}
{{ }}