Django:尝试使用Djangoex时发生意外的数据类型异常

2024-03-29 12:55:27 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我尝试使用django excel:https://github.com/pyexcel/django-excel 只需将某个模型导出到xls中。我根据文档设置了设置,但在运行时遇到以下错误:

Exception at /calbase/export/sheet
Unexpected data type <class 'django.db.models.fields.files.FieldFile'>

以下是我的观点:

^{pr2}$

当我想走的时候

http://127.0.0.1:8000/calbase/export/sheet

它给了我上面的例外。在

顺便问一下,有没有使用django excel的好例子?我好像无法运行提供的那个

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/calbase/export/sheet

Django Version: 1.10
Python Version: 3.5.2
Installed Applications:
['calbase.apps.CalbaseConfig',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'haystack',
 'whoosh',
 'carton']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 '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 "C:\Users\hansong.li\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\handlers\exception.py" in inner
  39.             response = get_response(request)

File "C:\Users\hansong.li\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\handlers\base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "C:\Users\hansong.li\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\handlers\base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\hansong.li\Documents\GitHub\equipCal\calbase\views.py" in export_data
  97.             Equipment, 'xls', file_name="sheet")

File "C:\Users\hansong.li\Documents\GitHub\equipCal\django_excel\__init__.py" in make_response_from_a_table
  147.                          file_name=file_name, **keywords)

File "C:\Users\hansong.li\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyexcel_webio\__init__.py" in make_response
  244.     file_stream = pyexcel_instance.save_to_memory(file_type, None, **keywords)

File "C:\Users\hansong.li\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyexcel\sheets\sheet.py" in save_to_memory
  114.         self.save_to(out_source)

File "C:\Users\hansong.li\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyexcel\sheets\sheet.py" in save_to
  79.         source.write_data(self)

File "C:\Users\hansong.li\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyexcel\sources\file_source_output.py" in write_data
  86.                                              sheet, **self.keywords)

File "C:\Users\hansong.li\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyexcel\sources\renderer\_excel.py" in render_sheet_to_stream
  35.                   **keywords)

File "C:\Users\hansong.li\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyexcel_io\io.py" in save_data
  70.                **keywords)

File "C:\Users\hansong.li\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyexcel_io\io.py" in store_data
  91.     writer.write(data)

File "C:\Users\hansong.li\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyexcel_io\book.py" in write
  177.                 sheet_writer.write_array(incoming_dict[sheet_name])

File "C:\Users\hansong.li\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyexcel_io\sheet.py" in write_array
  82.             self.write_row(row)

File "C:\Users\hansong.li\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyexcel_xls\xls.py" in write_row
  230.                 self.native_sheet.write(self.current_row, i, value)

File "C:\Users\hansong.li\AppData\Local\Programs\Python\Python35-32\lib\site-packages\xlwt\Worksheet.py" in write
  1033.         self.row(r).write(c, label, style)

File "C:\Users\hansong.li\AppData\Local\Programs\Python\Python35-32\lib\site-packages\xlwt\Row.py" in write
  263.             raise Exception("Unexpected data type %r" % type(label))

Exception Type: Exception at /calbase/export/sheet
Exception Value: Unexpected data type <class 'django.db.models.fields.files.FieldFile'>

Tags: djangoinpylibpackageslocalsiteli