views:

95

answers:

1

All,

I have the following in my views.py

def getgradeform(request):
   id1=request.user.get_pf().id
   sc=Sc.objects.filter(id=id1)
   logging.debug(sc)
   logging.debug("++++")
   dict={}
   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={{dict.sc}}/> //This also doesnt work.

Thanks......

+1  A: 

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

dict.key

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

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

{{ sc.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

{{ sc.name }}
{{ sc.id }}
Khelben
Thanks but i still have problems displaying it........Logging.debug gives an output as [<SC: Robert>](sorry not small case sc) and when i say {{sc.SC}} the output is null
Hulk
I figured it out thanks for the help.I used a for loop to display the value like the following {% for s in sc %} {{ s }} {% endfor %}
Hulk
OK, then you wanted to print all the values on the dictionary ;-)
Khelben
Yes :)....................
Hulk