gpt4 book ai didi

mysql - Django Admin 中的 PointField 使用 GeoDjango (DjangoUnicodeDecodeError)

转载 作者:行者123 更新时间:2023-11-29 07:58:54 30 4
gpt4 key购买 nike

我尝试使用 GeoDjango 包中的 PointField,每当我尝试查看具有已保存点的模型对象时,都会出现以下异常:

Environment:


Request Method: GET
Request URL: http://localhost:1989/admin/world/worldborder/6/

Django Version: 1.6.2
Python Version: 2.7.3
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'world')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
432. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
99. response = view_func(request, *args, **kwargs)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
52. response = view_func(request, *args, **kwargs)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
198. return view(request, *args, **kwargs)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
29. return bound_func(*args, **kwargs)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
99. response = view_func(request, *args, **kwargs)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
25. return func(self, *args2, **kwargs2)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/db/transaction.py" in inner
339. return func(*args, **kwargs)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in change_view
1237. form = ModelForm(instance=obj)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/forms/models.py" in __init__
315. object_data = model_to_dict(instance, opts.fields, opts.exclude)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/forms/models.py" in model_to_dict
143. data[f.name] = f.value_from_object(instance)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py" in value_from_object
560. return getattr(obj, self.attname)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/contrib/gis/db/models/proxy.py" in __get__
40. geom = self._klass(geom_value)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/contrib/gis/geos/geometry.py" in __init__
65. geo_input = force_text(geo_input)
File "/home/mark/.virtualenvs/fanmode/local/lib/python2.7/site-packages/django/utils/encoding.py" in force_text
116. raise DjangoUnicodeDecodeError(s, *e.args)

Exception Type: DjangoUnicodeDecodeError at /admin/world/worldborder/6/
Exception Value: 'utf8' codec can't decode byte 0xc0 in position 16: invalid start byte. You passed in '\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00,0\xc08\x00\x00\x00p\xdf\x19@' (<type 'str'>)

我的模型如下所示:

from django.contrib.gis.db import models

# Create your models here.
class WorldBorder(models.Model):
# Regular Django fields corresponding to the attributes in the
# world borders shapefile.
name = models.CharField(max_length=50)
location = models.PointField(null=False, blank=False, srid=4326, verbose_name="Location")


# Returns the string representation of the model.
# On Python 3: def __str__(self):
def __unicode__(self):
return self.name

我使用的是 MariaDB 5.5.38。 PointField 的表设置为 MyISAM,并且我尝试过编码 latin1 和 UTF-8。

有什么想法可能会导致这种情况吗?

谢谢,标记

最佳答案

答案是我忘记将这一关键行添加到模型中:

objects = models.GeoManager()

关于mysql - Django Admin 中的 PointField 使用 GeoDjango (DjangoUnicodeDecodeError),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24411432/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com