Сделал редирект 404 ошибки, если нет данных

This commit is contained in:
Данил 2024-09-18 21:27:26 +03:00
parent a3efc93df1
commit e4b236158c

View file

@ -1,5 +1,5 @@
from fastapi import APIRouter, Request
from fastapi.responses import HTMLResponse
from fastapi.responses import HTMLResponse, FileResponse
from fastapi.templating import Jinja2Templates
import requests
@ -11,12 +11,14 @@ template = Jinja2Templates(directory='./src/web/html')
@router.get('/wallpaper/{day}', response_class=HTMLResponse)
async def wallpaper(request: Request, day):
token = '1gI9G84ZafKDEnrbydviGknReOGiVK9jqrQBE3et'
res = requests.get('https://api.nasa.gov/planetary/apod', params={
'api_key': '1gI9G84ZafKDEnrbydviGknReOGiVK9jqrQBE3et',
'date': day,
})
if res.status_code != 200:
return FileResponse('./src/web/html/error/404.html')
return template.TemplateResponse(
request,
'/wallpaper.html',