I am currently building an app with Quart that web scrapes an external site for data. Because this can take several minutes, I made the scraping a background task to avoid request timeouts.
After the user provides a user ID to a form on the home page, the app sets a background task to scrape the data and in the meantime, the user is redirected to a loading page.
@app.route('/')
async def index():
form = await request.form
id = int(form['user_id'])
# set the background task
app.add_background_task(task_to_do, user_id=id)
return redirect('/loading')
@app.route('/loading')
async def loading():
return await render_template('loading.html')
Currently, the user is successfully redirected to the loading page and the scraping background task finishes no problem.
At the completion of my task_to_do
background task, I want the user to be redirected to a new page. How would one go about doing that?