restarting a flask application/ refreshing a template

Question:

I want to make a flask app restart when a POST request occurs.

My idea is a website where it’s a single index.html file, and the server writes the POSTed data.

A rough path for this is like so:

  1. Send Data to server –> 2. process data –> 3. write data to server –> 4. Restart the Flask instance/ Update the html

I’ve gotten to part 3. Part 4 doesn’t work for me, any method I try. Can someone help me?

I also used render_template, that’s probably the problem.

Current Code:

#Server-Side
@app.route("/", methods=["POST"])
def rnder():
  f = open("templates/index.html", "wt")
  f.write(str(request.json))
  f.close()
  f = open("restart.py", "rt")
  f = f.read()
  try:
    exec(f)
  except BrokenPipeError:
        sys.stdout = None
  quit()
  
@app.route("/", methods=["GET"])
def hello():
  return render_template('index.html')
#Sending Data
data = {"Hello World": "This is a test"}
requests.post(url="http://abcdefghijklmnopqrstuvw.xyz", json=data)
Asked By: Mikus Sturmanis

||

Answers:

adding debug=True did this. It refreshed on every update.

Answered By: Mikus Sturmanis
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.