Reputation: 37
I’m very new to Flask (and web development in general) but so far I think I’m sorta getting it?
anyway, I want to make a web app where the user uploads a file, the file will then be analyzed using Flask (mainly python and some shell) and the results then need to be reported back to the user.
I what have until now is a page where the user can upload their file and where a job id is assigned to the file. What I want next is that the users get redirected to a page with the jobid is the URL like
@app.route("/<jobid>", methods=['GET', 'POST’])
and that a loading page is displayed until the results files exist > then another page needs to be displayed.
The problem: I have no clue how to do that. This is what I got so far:
python:
@app.route("/<jobid>", methods=['GET', 'POST'])
def main_process(jobid):
if not jobid in JOBID_DICT:
return render_template("upload_fail.html")
else:
des = JOBID_DICT.get(jobid)
if request.method == "GET":
return render_template("complete.html", jobid=jobid)
if request.method == "POST": ##POST METHOD does not work yet
#this is where I need to run the analysis ig?
return render_template("results.html")
complete html:
{% extends "templates/base.html" %}
{% block title %}
succesfull upload
{% endblock %}
{% block main %}
<h1>file was uploaded</h1>
<p>starting process</p>
<p>once process is completed page will be refreshed.</p>
<p>Job ID: {{ jobid }} </p>
{% endblock %}
results.html:
{% extends "templates/base.html" %}
{% block title %}
{{jobid}}
{% endblock %}
{% block main %}
<h1>this the results page</h1>
<p>which I still need to code</p>
{% endblock %}
base.html (i use bootstrap and other css files but removed it for clarity):
<!doctype html>
<html lang="en">
<head>
<title> {% block title %}{% endblock %}</title>
</head>
<body>
<main>{% block main %}{% endblock %}</main>
</body>
</html>
If someone could help, it would be great. I mainly know python and R, and my HTML + CSS knowledge is from like 5 years ago… but I’m learning. Anyway thanks already.
Upvotes: 2
Views: 833
Reputation: 2117
You can use threading for that.
Put the job on a thread and when it completes update your UI
You can find more here threading
Upvotes: 1