I have set this FastApi server:
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles
from pathlib import Path
import requests
import mysql.connector as mariadb
from database import connection_properties as conn
mariadb_connection = mariadb.connect(user=conn.USER,
password=conn.PASSWORD,
host=conn.HOST,
database=conn.DATABASE,
auth_plugin='mysql_native_password')
cursor = mariadb_connection.cursor()
app = FastAPI()
templates = Jinja2Templates(directory="htmlPages")
app.mount(
"/htmlPages/static",
StaticFiles(directory=Path(__file__).parent.absolute() / "htmlPages" / "static"),
name="static",
)
@app.get("/county")
async def get_regions():
cursor.execute("SELECT name FROM county")
regions = cursor.fetchall()
return {"regions": regions}
@app.get("/")
async def home_page(req: Request):
return templates.TemplateResponse("homePage.html", {"request": req})
@app.get("/predictions", response_class=HTMLResponse)
async def predictions(request: Request):
response = requests.get("http://localhost:8000/county")
regions = response.json()["regions"]
return templates.TemplateResponse("predictions.html", {"request": request, "regions": regions})
The proble is that everytime I make a request at http://localhost:8000/predictions , the page seems like loading forever and I do not get anything. When I make a request at http://localhost:8000/county I receive the data that I want from the database. What is wrong?