Django Book 翻译
菜单>:
TOC
返回
原文:
As you can see, a ``__str__()`` method can do whatever it needs to do in order to return a string representation. Here, the ``__str__()`` methods for ``Publisher`` and ``Book`` simply return the objects name and title, respectively, but the ``__str__()`` for ``Author`` is slightly more complex it pieces together the ``first_name`` and ``last_name`` fields. The only requirement for ``__str__()`` is that it return a string. If ``__str__()`` doesnt return a string if it returns, say, an integer then Python will raise a ``TypeError`` with a message like ``"__str__ returned non-string"`` .
翻译:
就象你看到的一样, ``__str__()`` 方法返回一个字符串。 ``__str__()`` 必须返回字符串, 如果是其他类型,Python将会抛出 ``TypeError`` 错误消息 ``"__str__ returned non-string"`` 出来。
备注:
译者: