我正在尝试在GeoDjango中使用GeoAdmin。 我有一个表planet_osm_point,我想在管理界面中看到它。 我是django的初学者。
我有这个问题:
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 - - 位于我的文件顶部。 你能解释一下如何调试这个吗?
祝你好运 艾蒂安
答案 0 :(得分:11)
您有一个模型类,其__unicode__
方法正在返回None
。
确保它实际上有return
语句,而不是返回Unicode值。
答案 1 :(得分:1)
返回unicode的str(self.model_attribute)