2013-09-26 48 views
0

設置Django管理站點時,出現以下錯誤。我很難調試它,因爲我無法知道我的'公告'模型中發生問題的位置。我已經在發生問題的行上檢查了base.py,但我並不完全理解該類中正在發生的事情。Django在激活管理站點時拋出datetime.datetime沒有屬性編碼錯誤

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' 
+2

向我們展示您的'Announcement'模型的代碼。 – Rohan

回答

1

沒有看到你的Annoucement模型,這很難說,但似乎有可能,你是從你的__unicode__方法返回一個datetime,而不是實際的Unicode字符串。

+0

就是這樣,傻我,謝謝! – ohhh