@admin.register(Book)
class BookAdmin(ImportExportActionModelAdmin):
resource_class = BookResource
def get_import_form(self):
return CustomImportForm
def get_resource_kwargs(self, request, *args, **kwargs):
rk = super().get_resource_kwargs(request, *args, **kwargs)
rk['input_author'] = None
if request.POST:
author = request.POST.get('input_author', None)
if author:
request.session['input_author'] = author
else:
try:
author = request.session['input_author']
except KeyError as e:
raise Exception("Context failure on row import" + {e})
rk['input_author'] = author
return rk
在 django 管理页面中有此代码,但在导出过程中出现错误。谁能告诉我问题出在哪里?
最佳答案
您的问题在这一行:
raise Exception("Context failure on row import" + {e})
“{e}”表示您创建一个包含错误的集合,并尝试将其连接到异常消息字符串。您应该能够通过将“{e}”替换为“e”来消除该错误。
关于python - 不断收到此错误,不确定为什么 "Can' t 将 'set' 对象隐式转换为 str”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54612826/