Django在激活管理站点时抛出datetime.datetime没有属性编码错误

Django在激活管理站点时抛出datetime.datetime没有属性编码错误,django,datetime,attributes,django-admin,Django,Datetime,Attributes,Django Admin,在设置Django管理站点时,我遇到以下错误。我很难调试它,因为我不知道在我的“公告”模型中问题发生在哪里。我已经在出现问题的那一行检查了base.py,但我并不真正理解该类中发生的所有事情 Internal Server Error: /admin/main/announcment/ Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/bas

在设置Django管理站点时,我遇到以下错误。我很难调试它,因为我不知道在我的“公告”模型中问题发生在哪里。我已经在出现问题的那一行检查了base.py,但我并不真正理解该类中发生的所有事情

Internal Server Error: /admin/main/announcment/
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 140, in get_response
    response = response.render()
  File "/usr/local/lib/python2.7/dist-packages/django/template/response.py", line 105, in render
    self.content = self.rendered_content
  File "/usr/local/lib/python2.7/dist-packages/django/template/response.py", line 82, in rendered_content
    content = template.render(context)
  File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 140, in render
    return self._render(context)
  File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 134, in _render
    return self.nodelist.render(context)
  File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 830, in render
    bit = self.render_node(node, context)
  File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", line 74, in render_node
    return node.render(context)
  File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py", line 124, in render
    return compiled_parent._render(context)
  File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 134, in _render
    return self.nodelist.render(context)
  File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 830, in render
    bit = self.render_node(node, context)
  File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", line 74, in render_node
    return node.render(context)
  File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py", line 124, in render
    return compiled_parent._render(context)
  File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 134, in _render
    return self.nodelist.render(context)
  File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 830, in render
    bit = self.render_node(node, context)
  File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", line 74, in render_node
    return node.render(context)
  File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py", line 63, in render
    result = block.nodelist.render(context)
  File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 830, in render
    bit = self.render_node(node, context)
  File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", line 74, in render_node
    return node.render(context)
  File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py", line 63, in render
    result = block.nodelist.render(context)
  File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 830, in render
    bit = self.render_node(node, context)
  File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", line 74, in render_node
    return node.render(context)
  File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 1185, in render
    _dict = func(*resolved_args, **resolved_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templatetags/admin_list.py", line 286, in result_list
    'results': list(results(cl))}
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templatetags/admin_list.py", line 264, in results
    yield ResultList(None, items_for_result(cl, res, None))
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templatetags/admin_list.py", line 256, in __init__
    super(ResultList, self).__init__(*items)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templatetags/admin_list.py", line 184, in items_for_result
    f, attr, value = lookup_field(field_name, result, cl.model_admin)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/util.py", line 258, in lookup_field
    value = attr()
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 433, in __str__
    return force_text(self).encode('utf-8')
AttributeError: 'datetime.datetime' object has no attribute 'encode'

如果看不到您的公告模型,很难判断,但很可能您是从
\uuuuuUnicode\uuuuUnicode>方法返回了
日期时间
,而不是实际的unicode字符串。

显示您的
公告
模型的代码。