'NoneType'对象没有属性'encode' [英] 'NoneType' object has no attribute 'encode'
本文介绍了'NoneType'对象没有属性'encode'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在GeoDjango中使用GeoAdmin。
我有一个表planet_osm_point,我想在管理界面看到它。
我是django的初学者。
我有这个问题:
环境:
请求方法:GET
请求URL:http://127.0.0.1:8000/admin/api/planetosmpoint/
Django版本:1.5.1
Python版本:2.7.3
安装的应用程序:
('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')
安装的中间件:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django。 contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
模板错误:
在模板/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templates/admin/change_list.html中,第91行的错误
'NoneType'对象没有属性'encode'
81:{%endif%}
82:{%endblock%}
83:
84:< form id =changelist-formaction =method =post{%如果cl.formset.is_multipart%} enctype =multipart / form-data {%endif%}> {%csrf_token%}
85:{%如果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:
追溯:
文件/ usr / local / lib / python2.7 / dist-packages / django / core / handlers / base.pyin get_response
140. response = response.render()
文件/ usr / local / lib / python2.7 / dist-packages / django / template / response.py在render
105. self.content = self.rendered_content
文件/usr/local/lib/python2.7/ dist_package / django / template / response.py在rendered_content
82. content = template.render(context)
文件/usr/local/lib/python2.7/dist-packages/django /template/base.py在render
140. return self._render(context)
文件/usr/local/lib/python2.7/dist-packages/django/template/base.py in _render
134. return self.nodelist.render(context)
文件/usr/local/lib/python2.7/dist-packages/django/template/base.py在render
830. bit = self.render_node(node,context)
文件/ usr / loca lb / python2.7 / dist-packages / django / template / debug.py在render_node
中74.返回node.render(上下文)
文件/ usr / local / lib / python2 7 / dist-packages / django / template / loader_tags.pyin render
124. return compiled_parent._render(context)
文件/usr/local/lib/python2.7/dist-packages/ django / template / base.py在_render
134. return self.nodelist.render(context)
文件/usr/local/lib/python2.7/dist-packages/django/template/ render.py
830. base = self.render_node(node,context)
文件/usr/local/lib/python2.7/dist-packages/django/template/debug.py in render_node
74. return node.render(context)
文件/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py在render
124. return compiled_parent._render(context)
文件/usr/local/lib/python2.7/dist-packages/django/template/base.py在_render
134. return self。 nodelist.render(续ext)
文件/usr/local/lib/python2.7/dist-packages/django/template/base.py在render
830. bit = self.render_node(node,context)
文件/usr/local/lib/python2.7/dist-packages/django/template/debug.py在render_node
中74.返回node.render(上下文)
文件/在
中的$ usr / local / lib / python2.7 / dist-packages / django / template / loader_tags.py 63. result = block.nodelist.render(context)
文件/ usr / local render
830.bat = self.render_node(节点,上下文)
文件/ usr / local / lib /中的/lib/python2.7/dist-packages/django/template/base.py python2.7 / dist-packages / django / template / debug.pyin render_node
74. return node.render(context)
文件/usr/local/lib/python2.7/dist- render
中的包/ django / template / loader_tags.py63. result = block.nodelist.render(context)
文件/usr/local/lib/python2.7/dist-packages/django render
830中的/template/base.py。 bit = self.render_node(node,context)
文件/usr/local/lib/python2.7/dist-packages/django/template/debug.py在render_node
74.返回节点。 render(context)
文件/usr/local/lib/python2.7/dist-packages/django/template/base.py在render
1185. _dict = func(* resolved_args,** resolve_kwargs)
文件/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templatetags/admin_list.pyin result_list
286.'results':list(results (cl))}
结果中的文件/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templatetags/admin_list.py
264. yield ResultList(None ,items_for_result(cl,res,None))
文件/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templatetags/admin_list.py在__init__
256 。super(ResultList,self).__ init __(* items)
文件/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templatetags/admin_list.py在项目中s_for_result
184. f,attr,value = lookup_field(field_name,result,cl.model_admin)
文件/usr/local/lib/python2.7/dist-packages/django/contrib/admin/ util_field
258. value = attr()
__str__中的文件/usr/local/lib/python2.7/dist-packages/django/db/models/base.py
433. return force_text(self).encode('utf-8')
异常类型:/ admin / api / planetosmpoint /
处的AttributeError异常值:'NoneType'对象没有属性'encode'
我有# - - 编码:utf-8 - - 在我的文件的顶部。
你能解释一下如何调试这个吗?
最好的问候
Etienne
解决方案
您有一个模型类,其 __ unicode __
方法返回无
p>
确保它实际上具有返回Unicode值的返回
语句。
I'm trying to use GeoAdmin in GeoDjango. I have a table planet_osm_point and I would like to see it in the admin interface. I'm a beginner in django.
I have this problem :
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'
I have # -- coding: utf-8 -- at the top of my files. Can you explain me how to debug this ?
Best regards Etienne
解决方案
You have a model class whose __unicode__
method is returning None
.
Make sure it actually has a return
statement that returns a Unicode value instead.
这篇关于'NoneType'对象没有属性'encode'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文