python - How to get Object as String in Django? -


i'm trying simple thing couldn't find how to.

i have function defined in model class :

def __unicode__(self):     return "object name = " + self.name 

so in template page, or in views.py, want string.

in template, tried these , didn't work :

{{ my_object }} {{ str(my_object) }} {{ my_object.self }}

what correct way of doing this?

thanks !

there 2 functions __unicode__ , __str__ python class.

str function, in template, calls __str__.

class object(object):     name = "i'm object"      def __str__(self):         return "object name = %s" % self.name      def __unicode__(self):         return u"object name = %s" % self.name 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -