Django Book 翻译
菜单>:
TOC
返回
原文:
``__str__()`` is a Python magic method that defines what should be returned if you call ``str()`` on the object. Django uses ``str(obj)`` (or the related function, ``unicode(obj)`` , described shortly) in a number of places, most notably as the value displayed to render an object in the Django admin site and as the value inserted into a template when it displays an object. Thus, you should always return a nice, human-readable string for the objects ``__str__`` . Although this isnt required, its strongly encouraged.
翻译:
__str__()是一個Python 魔術的方法,它定義了什麼東西将会被返回假如你调用这个对象的str()。Django 使用str(obj)(或是相對應的函數,unicode(obj),簡短地描述),在很多地方,最有名,是這秀出來的值被這個物件重繪在Django 管理站,而且被寫入樣板的值,當它展示一個物件。因此,你必須總是返回一個好的,人類可讀的字串,對這個物件__str__。即使這不是必須的,它還是強列地被鼓勵 。
备注:
译者: