python - 不断收到此错误,不确定为什么 "Can' t 将 'set' 对象隐式转换为 str”

标签 python django django-sessions

@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 管理页面中有此代码,但在导出过程中出现错误。谁能告诉我问题出在哪里?

enter image description here

最佳答案

您的问题在这一行:

raise Exception("Context failure on row import" + {e})

“{e}”表示您创建一个包含错误的集合,并尝试将其连接到异常消息字符串。您应该能够通过将“{e}”替换为“e”来消除该错误。

关于python - 不断收到此错误,不确定为什么 "Can' t 将 'set' 对象隐式转换为 str”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54612826/

相关文章:

python - 手动验证 django session id 当前已通过身份验证

python - 操作错误 : cursor "_django_curs_<id>" does not exist

django - 如何在 Django session 中存储表单输入?

python - 如何添加一个 id 列来识别 read_html() 表?

python - 与 pandas 中的组一起操作

python - 当每个任务有不同数量的数据样本时,是否可以制作多输入和多输出 DNN 模型

python - tensorflow 简单逻辑回归

javascript - 在导航栏中显示未读计数

python - 使用 Django 下载 xlsx 格式的 SQL 数据