2013-05-17 192 views
0

我想在GeoDjango中使用GeoAdmin。 我有一个表planet_osm_point,我想在管理界面中看到它。 我是django的初学者。'NoneType'对象没有属性'编码'

我有这样的问题:

Environment: 


Request Method: GET 
Request URL: http://127.0.0.1:8000/admin/api/planetosmpoint/ 

Django Version: 1.5.1 
Python Version: 2.7.3 
Installed Applications: 
('django.contrib.auth', 
'django.contrib.contenttypes', 
'django.contrib.sessions', 
'django.contrib.sites', 
'django.contrib.messages', 
'django.contrib.staticfiles', 
'django.contrib.admin', 
'django.contrib.gis', 
'api', 
'portail') 
Installed Middleware: 
('django.middleware.common.CommonMiddleware', 
'django.contrib.sessions.middleware.SessionMiddleware', 
'django.middleware.csrf.CsrfViewMiddleware', 
'django.contrib.auth.middleware.AuthenticationMiddleware', 
'django.contrib.messages.middleware.MessageMiddleware') 


Template error: 
In template /usr/local/lib/python2.7/dist-packages/django/contrib/admin/templates/admin/change_list.html, error at line 91 
    'NoneType' object has no attribute 'encode' 
    81 :   {% endif %} 


    82 :  {% endblock %} 


    83 : 


    84 :  <form id="changelist-form" action="" method="post"{% if cl.formset.is_multipart %} enctype="multipart/form-data"{% endif %}>{% csrf_token %} 


    85 :  {% if cl.formset %} 


    86 :   <div>{{ cl.formset.management_form }}</div> 


    87 :  {% endif %} 


    88 : 


    89 :  {% block result_list %} 


    90 :   {% if action_form and actions_on_top and cl.full_result_count %}{% admin_actions %}{% endif %} 


    91 :   {% result_list cl %} 


    92 :   {% if action_form and actions_on_bottom and cl.full_result_count %}{% admin_actions %}{% endif %} 


    93 :  {% endblock %} 


    94 :  {% block pagination %}{% pagination cl %}{% endblock %} 


    95 :  </form> 


    96 :  </div> 


    97 : </div> 


    98 : {% endblock %} 


    99 : 

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

Exception Type: AttributeError at /admin/api/planetosmpoint/ 
Exception Value: 'NoneType' object has no attribute 'encode' 

我# - - 编码:UTF-8 - - 在我的文件上。 你能解释一下如何调试吗?

问候 艾蒂安

回答

11

您有其__unicode__方法返回None模型类。

确保它实际上有一个return语句,它返回一个Unicode值。

+0

谢谢!我更了解django是如何工作的。 – Gustry

1

unicode的返回str(self.model_attribute)

相关问题