mirror of
https://github.com/Starlio-app/Starlio-web.git
synced 2024-11-21 16:26:21 +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 import APIRouter, Request
|
||||||
from fastapi.responses import HTMLResponse
|
from fastapi.responses import HTMLResponse, FileResponse
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
@ -11,12 +11,14 @@ template = Jinja2Templates(directory='./src/web/html')
|
||||||
|
|
||||||
@router.get('/wallpaper/{day}', response_class=HTMLResponse)
|
@router.get('/wallpaper/{day}', response_class=HTMLResponse)
|
||||||
async def wallpaper(request: Request, day):
|
async def wallpaper(request: Request, day):
|
||||||
token = '1gI9G84ZafKDEnrbydviGknReOGiVK9jqrQBE3et'
|
|
||||||
res = requests.get('https://api.nasa.gov/planetary/apod', params={
|
res = requests.get('https://api.nasa.gov/planetary/apod', params={
|
||||||
'api_key': '1gI9G84ZafKDEnrbydviGknReOGiVK9jqrQBE3et',
|
'api_key': '1gI9G84ZafKDEnrbydviGknReOGiVK9jqrQBE3et',
|
||||||
'date': day,
|
'date': day,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if res.status_code != 200:
|
||||||
|
return FileResponse('./src/web/html/error/404.html')
|
||||||
|
|
||||||
return template.TemplateResponse(
|
return template.TemplateResponse(
|
||||||
request,
|
request,
|
||||||
'/wallpaper.html',
|
'/wallpaper.html',
|
||||||
|
|
Loading…
Add table
Reference in a new issue