如何使用数据重定向到另一个页面?从 FastAPI 文档,我已阅读重定向到另一个 URL 必须使用 RedirectResponse()
@app.post('/update/{book_id}')
async def update_post(
title = Form(...),
author = Form(...),
published_date = Form(...),
isbn = Form(...),
page_count = Form(...),
preview_url = Form(...),
publication_language = Form(...),
book_id: int = 0,
):
try:
book: Book = await Book.objects.get(id=book_id)
except ormar.exceptions.NoMatch:
return status.HTTP_404_NOT_FOUND
await book.update(
title=title,
author=author,
published_date=published_date,
isbn=isbn,
page_count=page_count,
preview_url=preview_url,
publication_language=publication_language
)
return RedirectResponse(url='/', status_code=status.HTTP_303_SEE_OTHER , headers={'message': 'Book has been successfully updated!'})
return RedirectResponse(url='/', status_code=status.HTTP_303_SEE_OTHER , headers={'message': 'Book has been successfully updated!'})
这没有用。我无法在 / 端点中读取此数据
print(dict(request.__dict__['scope']['headers'])['message'])
给我
KeyError: 'message'