Djnago ninja | Trying to send file | no validator found for <class 'django.http.response.HttpResponse'>, see `arbitrary_types_allowed` in Config

хорошие люди,

Я пытаюсь реализовать функциональность загрузки файлов. И код довольно прост:

@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

Я не хочу устанавливать arbitrary_types_allowed.

Как я могу решить эту проблему?

Согласно: https://github.com/vitalik/django-ninja/issues/424#issuecomment-1099930539

удалите эту часть

, response=HttpResponse)

И это действительно сработало

Вернуться на верх