当我尝试通过xadmin页面从模型导出数据时出现此错误。
Class ModelAdmin(object):
reversion_enable = True
list_display = (
'name', 'description', 'pref_name', 'target_type', 'organism', 'tax_id', 'chembl_id', 'uniprot_accession')
search_fields = ['name', 'description', 'chembl_id', 'uniprot_accession', 'pref_name']
style_fields = {'description': "rich-textarea"}
list_export = ('xls', 'xml', 'json', 'csv')
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/xadmin/idg/moleculedictionary/?_do_=export&export_type=xls&export_xls_header=on
Django Version: 1.7.8
Python Version: 2.7.9
Installed Applications:
('idg',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.sites',
'django_comments',
'django_countries',
'xadmin',
'crispy_forms',
'reversion',
'django.contrib.staticfiles',
'debug_toolbar')
Installed Middleware:
(u'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'reversion.middleware.RevisionMiddleware')
Traceback:
File "/home/idg/.virtualenvs/idg/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/idg/.virtualenvs/idg/local/lib/python2.7/site-packages/xadmin/sites.py" in wrapper
291. return self.admin_view(view, cacheable)(*args, **kwargs)
File "/home/idg/.virtualenvs/idg/local/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
52. response = view_func(request, *args, **kwargs)
File "/home/idg/.virtualenvs/idg/local/lib/python2.7/site-packages/xadmin/sites.py" in inner
199. return view(request, *args, **kwargs)
File "/home/idg/.virtualenvs/idg/local/lib/python2.7/site-packages/xadmin/views/base.py" in view
256. return handler(request, *args, **kwargs)
File "/home/idg/.virtualenvs/idg/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
29. return bound_func(*args, **kwargs)
File "/home/idg/.virtualenvs/idg/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
105. response = view_func(request, *args, **kwargs)
File "/home/idg/.virtualenvs/idg/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
25. return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/idg/.virtualenvs/idg/local/lib/python2.7/site-packages/xadmin/views/base.py" in method
72. return filter_chain(filters, len(filters) - 1, _inner_method, *args, **kwargs)
File "/home/idg/.virtualenvs/idg/local/lib/python2.7/site-packages/xadmin/views/base.py" in filter_chain
41. return func()
File "/home/idg/.virtualenvs/idg/local/lib/python2.7/site-packages/xadmin/views/base.py" in _inner_method
66. return func(self, *args, **kwargs)
File "/home/idg/.virtualenvs/idg/local/lib/python2.7/site-packages/xadmin/views/list.py" in get
412. response = self.get_response(context, *args, **kwargs)
File "/home/idg/.virtualenvs/idg/local/lib/python2.7/site-packages/xadmin/views/base.py" in method
72. return filter_chain(filters, len(filters) - 1, _inner_method, *args, **kwargs)
File "/home/idg/.virtualenvs/idg/local/lib/python2.7/site-packages/xadmin/views/base.py" in filter_chain
55. return filter_chain(filters, token - 1, _inner_method, *args, **kwargs)
File "/home/idg/.virtualenvs/idg/local/lib/python2.7/site-packages/xadmin/views/base.py" in filter_chain
41. return func()
File "/home/idg/.virtualenvs/idg/local/lib/python2.7/site-packages/xadmin/views/base.py" in _inner_method
54. return fm(func if fargs[1] == '__' else func(), *args, **kwargs)
File "/home/idg/.virtualenvs/idg/local/lib/python2.7/site-packages/xadmin/plugins/export.py" in get_response
218. mimetype="%s; charset=UTF-8" % self.export_mimes[file_type])
File "/home/idg/.virtualenvs/idg/local/lib/python2.7/site-packages/django/http/response.py" in __init__
318. super(HttpResponse, self).__init__(*args, **kwargs)
Exception Type: TypeError at /xadmin/idg/moleculedictionary/
Exception Value: __init__() got an unexpected keyword argument 'mimetype'
我已按照xadmin文档中的建议添加了list_export。但帮助不大。 我究竟做错了什么?任何建议都会得到很大的启发。感谢。
答案 0 :(得分:1)
您安装的xadmin版本与Django 1.7+不兼容它使用的mimetype
参数为removed in Django 1.7。
问题一直是fixed in the master branch,但从那时起看起来并没有新版本。
你可以尝试安装master分支,但我会谨慎使用一个没有发布这么久的应用程序,除非你有信心调试这样的问题。