mirror of
https://github.com/Starlio-app/Starlio-web.git
synced 2024-12-24 17:33:45 +03:00
Сделал редирект 404 ошибки, если нет данных
This commit is contained in:
parent
a3efc93df1
commit
e4b236158c
1 changed files with 4 additions and 2 deletions
|
@ -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',
|
||||
|
|
Loading…
Add table
Reference in a new issue