Reputation: 849
I'am trying to display data from the database file which has the value Age : 50 but i alway get "Age object" displayed in the html. I'm very new too Django. Here is the code
//base.HTML displays :
Age object
//base.html code :
<body>
{{ obj }}
</body>
//views.py :
def home(request):
obj = Age.objects.all()
return render_to_response("base.html",{'obj': obj})
//models.py
class Age(models.Model):
age = models.CharField(max_length=100)
Upvotes: 0
Views: 1662
Reputation: 785
simply obj
is an array of objects, you have to print the attribute of the object.
If you want to show only one age
(the first) you have to do:
//views.py :
def home(request):
obj = Age.objects.all()[0]
return render_to_response("base.html",{'obj': obj})
//base.html code :
<body>
{{ obj.age }}
</body>
Upvotes: 3
Reputation: 1562
You need to either do obj.age in the template, or implement str or unicode method on your object that returns the age.
Upvotes: 1