我试图调试此问题,但现有的答案都没有帮助。当我运行Django服务器时,我看到了:
'module' object has no attribute 'OSMGeoAdmin'
我知道this question是同样的错误,但django.contrib.gis.admin导入正确,我在Mac上开发,而不是在Windows上开发。我安装了gdal以及geos。我已经多次运行此应用程序并且之前没有看到错误。正确安装和配置GDAL,并正确设置路径。 Geos已安装。我已经清除了我的虚拟环境,重新启动并重新安装,但无济于事。
令人沮丧的是,我能够让应用程序正常运行,直到我开始使用sorl-thumbnail解决问题。看看我的bash历史,我确实尝试像这样安装jpegsrc(和PIL一样pip install PIL --allow-unverified PIL --allow-all-external
):
curl -O http://www.ijg.org/files/jpegsrc.v8c.tar.gz
tar zxvf jpegsrc.v8c.tar.gz
cd jpeg-8c/
./configure
make
sudo make install
感谢您提供的任何帮助。
完整追溯:
Request Method: GET
Request URL: http://0.0.0.0:8003/
Django Version: 1.5.4
Python Version: 2.7.5
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'grappelli',
'django.contrib.admin',
'django.contrib.markup',
'django.contrib.humanize',
'django.contrib.gis',
'south',
'parks',
'sorl.thumbnail')
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')
Traceback:
File "/Users/mapcuser/.venvs/bostongreenmap/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
103. resolver_match = resolver.resolve(request.path_info)
File "/Users/mapcuser/.venvs/bostongreenmap/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
319. for pattern in self.url_patterns:
File "/Users/mapcuser/.venvs/bostongreenmap/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns
347. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/mapcuser/.venvs/bostongreenmap/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
342. self._urlconf_module = import_module(self.urlconf_name)
File "/Users/mapcuser/.venvs/bostongreenmap/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/Volumes/public/DataServices/Code/Django/BostonGreen/bostongreenmap/bostongreenmap/urls.py" in <module>
9. admin.autodiscover()
File "/Users/mapcuser/.venvs/bostongreenmap/lib/python2.7/site-packages/django/contrib/admin/__init__.py" in autodiscover
29. import_module('%s.admin' % app)
File "/Users/mapcuser/.venvs/bostongreenmap/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/Volumes/public/DataServices/Code/Django/BostonGreen/bostongreenmap/parks/admin.py" in <module>
13. class ParkAdmin(admin.OSMGeoAdmin):
Exception Type: AttributeError at /
Exception Value: 'module' object has no attribute 'OSMGeoAdmin'
admin.py:
from django.contrib.gis import admin
from parks.models import Facility, Neighborhood, Park, Activity, Event, Parktype, Parkowner, Parkimage, Facilitytype, Friendsgroup, Story
from sorl.thumbnail import default
from django.conf import settings
# default GeoAdmin overloads
admin.GeoModelAdmin.default_lon = -7912100
admin.GeoModelAdmin.default_lat = 5210000
admin.GeoModelAdmin.default_zoom = 11
class ParkAdmin(admin.OSMGeoAdmin):
list_display = ['name', 'parkowner' ]
list_filter = ('neighborhoods', )
search_fields = ['name']
exclude = ('slug', )
def park_image_thumb(self, obj):
if obj.image:
thumb = default.backend.get_thumbnail(obj.image.file, settings.ADMIN_THUMBS_SIZE)
return u'<img width="%s" src="%s" />' % (thumb.width, thumb.url)
else:
return "No Image"
park_image_thumb.short_description = 'Park Image'
park_image_thumb.allow_tags = True
readonly_fields = ['park_image_thumb',]
class FacilityAdmin(admin.OSMGeoAdmin):
search_fields = ['name', 'park__name']
exclude = ('park',)
list_display = ['pk', 'name', 'activity_string', 'facilitytype', ]
list_editable = ['name', 'facilitytype', ]
list_filter = ('activity', )
class LookupAdmin(admin.ModelAdmin):
def ic(self, obj):
if hasattr(obj, 'icon'):
thumb = default.backend.get_thumbnail(obj.icon.file,"24")
return u'<img width="%s" src="%s" />' % (thumb.width, thumb.url)
else:
return ""
ic.short_description = 'Park Image'
ic.allow_tags = True
list_display = ['id', 'name','ic' ]
list_editable = ['name', ]
class ParkimageAdmin(admin.ModelAdmin):
list_display = ['pk', 'thumbnail', 'caption', 'get_parks_string' ]
list_editable = ['caption', ]
search_fields = ['caption', ]
readonly_fields = ('thumbnail',)
list_per_page = 20
#admin.site.register(Greenspace, admin.OSMGeoAdmin)
admin.site.register(Facility, FacilityAdmin)
admin.site.register(Facilitytype, LookupAdmin)
admin.site.register(Park, ParkAdmin)
admin.site.register(Parktype, LookupAdmin)
admin.site.register(Parkowner, LookupAdmin)
admin.site.register(Parkimage, ParkimageAdmin)
admin.site.register(Neighborhood, admin.OSMGeoAdmin)
admin.site.register(Activity, LookupAdmin)
admin.site.register(Event)
admin.site.register(Friendsgroup)
admin.site.register(Story)
答案 0 :(得分:0)
您需要在每个子类中指定类属性重载,如下所示:
class FacilityAdmin(admin.OSMGeoAdmin):
default_lon = -7912100
default_lat = 5210000
default_zoom = 11
search_fields = ['name', 'park__name']
exclude = ('park',)
list_display = ['pk', 'name', 'activity_string', 'facilitytype', ]
list_editable = ['name', 'facilitytype', ]
list_filter = ('activity', )
答案 1 :(得分:0)
此错误:'module'对象没有属性'OSMGeoAdmin'
来自admin.py
只添加.g就是这样:
来自django.contrib.gis import admin