djnago忍者|尝试发送文件|找不到< class' django.http.response.httpresponse>>,请参见coniform
好人,
我正在尝试实现文件下载功能。而且代码非常简单:
@api.get("/summary/", response=HttpResponse)
def report_summary(
request: NinjaRequest, start_date: str, end_date: str
) -> HttpResponse:
...
response = HttpResponse(
output, # output is the file
content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
)
response["Content-Disposition"] = f"attachment; filename={fname}" # fname is the name of the file
return response
但是在启动过程中,我说的是一个错误:
RuntimeError: no validator found for <class 'django.http.response.HttpResponse'>, see `arbitrary_types_allowed` in Config
我不想设置 nuterary_types_lowled
。。
现在如何解决此问题?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据:
删除此部分
,实际上起作用
According to: https://github.com/vitalik/django-ninja/issues/424#issuecomment-1099930539
remove this part
And it actually worked