We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Setup: generated files missing
Traefik is ending up in a looped redirect when trying to download the generated files. Flask blueprint context to be modified to simplify the forwarding and eliminate the need for redirects.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `setup/server.py`
Content:
```
1 import flask
2 import flask_bootstrap
3 import redis
4 import json
5 import os
6 import jinja2
7 import uuid
8 import string
9 import random
10 import ipaddress
11 
12 
13 app = flask.Flask(__name__)
14 flask_bootstrap.Bootstrap(app)
15 db = redis.StrictRedis(host='redis', port=6379, db=0)
16 
17 
18 def render_flavor(flavor, template, data):
19     return flask.render_template(
20         os.path.join(flavor, template),
21         **data
22     )
23 
24 
25 @app.add_template_global
26 def secret(length=16):
27     charset = string.ascii_uppercase + string.digits
28     return ''.join(
29         random.SystemRandom().choice(charset)
30         for _ in range(length)
31     )
32 
33 
34 def build_app(path):
35 
36     app.jinja_env.trim_blocks = True
37     app.jinja_env.lstrip_blocks = True
38 
39     @app.context_processor
40     def app_context():
41         return dict(versions=os.getenv("VERSIONS","master").split(','))
42 
43     version = os.getenv("this_version")
44 
45     bp = flask.Blueprint(version, __name__)
46     bp.jinja_loader = jinja2.ChoiceLoader([
47         jinja2.FileSystemLoader(os.path.join(path, "templates")),
48         jinja2.FileSystemLoader(os.path.join(path, "flavors"))
49     ])
50 
51     @bp.context_processor
52     def bp_context(version=version):
53         return dict(version=version)
54 
55     @bp.route("/")
56     def wizard():
57         return flask.render_template('wizard.html')
58 
59     @bp.route("/submit_flavor", methods=["POST"])
60     def submit_flavor():
61         data = flask.request.form.copy()
62         steps = sorted(os.listdir(os.path.join(path, "templates", "steps", data["flavor"])))
63         return flask.render_template('wizard.html', flavor=data["flavor"], steps=steps)
64 
65     @bp.route("/submit", methods=["POST"])
66     def submit():
67         data = flask.request.form.copy()
68         data['uid'] = str(uuid.uuid4())
69         data['dns'] = str(ipaddress.IPv4Network(data['subnet'])[-2])
70         db.set(data['uid'], json.dumps(data))
71         return flask.redirect(flask.url_for('.setup', uid=data['uid']))
72 
73     @bp.route("/setup/<uid>", methods=["GET"])
74     def setup(uid):
75         data = json.loads(db.get(uid))
76         flavor = data.get("flavor", "compose")
77         rendered = render_flavor(flavor, "setup.html", data)
78         return flask.render_template("setup.html", contents=rendered)
79 
80     @bp.route("/file/<uid>/<filepath>", methods=["GET"])
81     def file(uid, filepath):
82         data = json.loads(db.get(uid))
83         flavor = data.get("flavor", "compose")
84         return flask.Response(
85             render_flavor(flavor, filepath, data),
86             mimetype="application/text"
87         )
88 
89     app.register_blueprint(bp, url_prefix="/{}".format(version))
90 
91 
92 if __name__ == "__main__":
93     build_app("/tmp/mailutest")
94     app.run(debug=True)
95
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/setup/server.py b/setup/server.py
--- a/setup/server.py
+++ b/setup/server.py
@@ -10,7 +10,9 @@
 import ipaddress
 
 
-app = flask.Flask(__name__)
+version = os.getenv("this_version")
+static_url_path = "/" + version + "/static"
+app = flask.Flask(__name__, static_url_path=static_url_path)
 flask_bootstrap.Bootstrap(app)
 db = redis.StrictRedis(host='redis', port=6379, db=0)
 
@@ -40,29 +42,37 @@
     def app_context():
         return dict(versions=os.getenv("VERSIONS","master").split(','))
 
-    version = os.getenv("this_version")
+    prefix_bp = flask.Blueprint(version, __name__)
+    prefix_bp.jinja_loader = jinja2.ChoiceLoader([
+        jinja2.FileSystemLoader(os.path.join(path, "templates")),
+        jinja2.FileSystemLoader(os.path.join(path, "flavors"))
+    ])
 
-    bp = flask.Blueprint(version, __name__)
-    bp.jinja_loader = jinja2.ChoiceLoader([
+    root_bp = flask.Blueprint("root", __name__)
+    root_bp.jinja_loader = jinja2.ChoiceLoader([
         jinja2.FileSystemLoader(os.path.join(path, "templates")),
         jinja2.FileSystemLoader(os.path.join(path, "flavors"))
     ])
 
-    @bp.context_processor
+    @prefix_bp.context_processor
+    @root_bp.context_processor
     def bp_context(version=version):
         return dict(version=version)
 
-    @bp.route("/")
+    @prefix_bp.route("/")
+    @root_bp.route("/")
     def wizard():
         return flask.render_template('wizard.html')
 
-    @bp.route("/submit_flavor", methods=["POST"])
+    @prefix_bp.route("/submit_flavor", methods=["POST"])
+    @root_bp.route("/submit_flavor", methods=["POST"])
     def submit_flavor():
         data = flask.request.form.copy()
         steps = sorted(os.listdir(os.path.join(path, "templates", "steps", data["flavor"])))
         return flask.render_template('wizard.html', flavor=data["flavor"], steps=steps)
 
-    @bp.route("/submit", methods=["POST"])
+    @prefix_bp.route("/submit", methods=["POST"])
+    @root_bp.route("/submit", methods=["POST"])
     def submit():
         data = flask.request.form.copy()
         data['uid'] = str(uuid.uuid4())
@@ -70,14 +80,16 @@
         db.set(data['uid'], json.dumps(data))
         return flask.redirect(flask.url_for('.setup', uid=data['uid']))
 
-    @bp.route("/setup/<uid>", methods=["GET"])
+    @prefix_bp.route("/setup/<uid>", methods=["GET"])
+    @root_bp.route("/setup/<uid>", methods=["GET"])
     def setup(uid):
         data = json.loads(db.get(uid))
         flavor = data.get("flavor", "compose")
         rendered = render_flavor(flavor, "setup.html", data)
         return flask.render_template("setup.html", contents=rendered)
 
-    @bp.route("/file/<uid>/<filepath>", methods=["GET"])
+    @prefix_bp.route("/file/<uid>/<filepath>", methods=["GET"])
+    @root_bp.route("/file/<uid>/<filepath>", methods=["GET"])
     def file(uid, filepath):
         data = json.loads(db.get(uid))
         flavor = data.get("flavor", "compose")
@@ -86,7 +98,8 @@
             mimetype="application/text"
         )
 
-    app.register_blueprint(bp, url_prefix="/{}".format(version))
+    app.register_blueprint(prefix_bp, url_prefix="/{}".format(version))
+    app.register_blueprint(root_bp)
 
 
 if __name__ == "__main__":

{"golden_diff": "diff --git a/setup/server.py b/setup/server.py\n--- a/setup/server.py\n+++ b/setup/server.py\n@@ -10,7 +10,9 @@\n import ipaddress\n \n \n-app = flask.Flask(__name__)\n+version = os.getenv(\"this_version\")\n+static_url_path = \"/\" + version + \"/static\"\n+app = flask.Flask(__name__, static_url_path=static_url_path)\n flask_bootstrap.Bootstrap(app)\n db = redis.StrictRedis(host='redis', port=6379, db=0)\n \n@@ -40,29 +42,37 @@\n     def app_context():\n         return dict(versions=os.getenv(\"VERSIONS\",\"master\").split(','))\n \n-    version = os.getenv(\"this_version\")\n+    prefix_bp = flask.Blueprint(version, __name__)\n+    prefix_bp.jinja_loader = jinja2.ChoiceLoader([\n+        jinja2.FileSystemLoader(os.path.join(path, \"templates\")),\n+        jinja2.FileSystemLoader(os.path.join(path, \"flavors\"))\n+    ])\n \n-    bp = flask.Blueprint(version, __name__)\n-    bp.jinja_loader = jinja2.ChoiceLoader([\n+    root_bp = flask.Blueprint(\"root\", __name__)\n+    root_bp.jinja_loader = jinja2.ChoiceLoader([\n         jinja2.FileSystemLoader(os.path.join(path, \"templates\")),\n         jinja2.FileSystemLoader(os.path.join(path, \"flavors\"))\n     ])\n \n-    @bp.context_processor\n+    @prefix_bp.context_processor\n+    @root_bp.context_processor\n     def bp_context(version=version):\n         return dict(version=version)\n \n-    @bp.route(\"/\")\n+    @prefix_bp.route(\"/\")\n+    @root_bp.route(\"/\")\n     def wizard():\n         return flask.render_template('wizard.html')\n \n-    @bp.route(\"/submit_flavor\", methods=[\"POST\"])\n+    @prefix_bp.route(\"/submit_flavor\", methods=[\"POST\"])\n+    @root_bp.route(\"/submit_flavor\", methods=[\"POST\"])\n     def submit_flavor():\n         data = flask.request.form.copy()\n         steps = sorted(os.listdir(os.path.join(path, \"templates\", \"steps\", data[\"flavor\"])))\n         return flask.render_template('wizard.html', flavor=data[\"flavor\"], steps=steps)\n \n-    @bp.route(\"/submit\", methods=[\"POST\"])\n+    @prefix_bp.route(\"/submit\", methods=[\"POST\"])\n+    @root_bp.route(\"/submit\", methods=[\"POST\"])\n     def submit():\n         data = flask.request.form.copy()\n         data['uid'] = str(uuid.uuid4())\n@@ -70,14 +80,16 @@\n         db.set(data['uid'], json.dumps(data))\n         return flask.redirect(flask.url_for('.setup', uid=data['uid']))\n \n-    @bp.route(\"/setup/<uid>\", methods=[\"GET\"])\n+    @prefix_bp.route(\"/setup/<uid>\", methods=[\"GET\"])\n+    @root_bp.route(\"/setup/<uid>\", methods=[\"GET\"])\n     def setup(uid):\n         data = json.loads(db.get(uid))\n         flavor = data.get(\"flavor\", \"compose\")\n         rendered = render_flavor(flavor, \"setup.html\", data)\n         return flask.render_template(\"setup.html\", contents=rendered)\n \n-    @bp.route(\"/file/<uid>/<filepath>\", methods=[\"GET\"])\n+    @prefix_bp.route(\"/file/<uid>/<filepath>\", methods=[\"GET\"])\n+    @root_bp.route(\"/file/<uid>/<filepath>\", methods=[\"GET\"])\n     def file(uid, filepath):\n         data = json.loads(db.get(uid))\n         flavor = data.get(\"flavor\", \"compose\")\n@@ -86,7 +98,8 @@\n             mimetype=\"application/text\"\n         )\n \n-    app.register_blueprint(bp, url_prefix=\"/{}\".format(version))\n+    app.register_blueprint(prefix_bp, url_prefix=\"/{}\".format(version))\n+    app.register_blueprint(root_bp)\n \n \n if __name__ == \"__main__\":\n", "issue": "Setup: generated files missing\nTraefik is ending up in a looped redirect when trying to download the generated files. Flask blueprint context to be modified to simplify the forwarding and eliminate the need for redirects.\n", "before_files": [{"content": "import flask\nimport flask_bootstrap\nimport redis\nimport json\nimport os\nimport jinja2\nimport uuid\nimport string\nimport random\nimport ipaddress\n\n\napp = flask.Flask(__name__)\nflask_bootstrap.Bootstrap(app)\ndb = redis.StrictRedis(host='redis', port=6379, db=0)\n\n\ndef render_flavor(flavor, template, data):\n    return flask.render_template(\n        os.path.join(flavor, template),\n        **data\n    )\n\n\n@app.add_template_global\ndef secret(length=16):\n    charset = string.ascii_uppercase + string.digits\n    return ''.join(\n        random.SystemRandom().choice(charset)\n        for _ in range(length)\n    )\n\n\ndef build_app(path):\n\n    app.jinja_env.trim_blocks = True\n    app.jinja_env.lstrip_blocks = True\n\n    @app.context_processor\n    def app_context():\n        return dict(versions=os.getenv(\"VERSIONS\",\"master\").split(','))\n\n    version = os.getenv(\"this_version\")\n\n    bp = flask.Blueprint(version, __name__)\n    bp.jinja_loader = jinja2.ChoiceLoader([\n        jinja2.FileSystemLoader(os.path.join(path, \"templates\")),\n        jinja2.FileSystemLoader(os.path.join(path, \"flavors\"))\n    ])\n\n    @bp.context_processor\n    def bp_context(version=version):\n        return dict(version=version)\n\n    @bp.route(\"/\")\n    def wizard():\n        return flask.render_template('wizard.html')\n\n    @bp.route(\"/submit_flavor\", methods=[\"POST\"])\n    def submit_flavor():\n        data = flask.request.form.copy()\n        steps = sorted(os.listdir(os.path.join(path, \"templates\", \"steps\", data[\"flavor\"])))\n        return flask.render_template('wizard.html', flavor=data[\"flavor\"], steps=steps)\n\n    @bp.route(\"/submit\", methods=[\"POST\"])\n    def submit():\n        data = flask.request.form.copy()\n        data['uid'] = str(uuid.uuid4())\n        data['dns'] = str(ipaddress.IPv4Network(data['subnet'])[-2])\n        db.set(data['uid'], json.dumps(data))\n        return flask.redirect(flask.url_for('.setup', uid=data['uid']))\n\n    @bp.route(\"/setup/<uid>\", methods=[\"GET\"])\n    def setup(uid):\n        data = json.loads(db.get(uid))\n        flavor = data.get(\"flavor\", \"compose\")\n        rendered = render_flavor(flavor, \"setup.html\", data)\n        return flask.render_template(\"setup.html\", contents=rendered)\n\n    @bp.route(\"/file/<uid>/<filepath>\", methods=[\"GET\"])\n    def file(uid, filepath):\n        data = json.loads(db.get(uid))\n        flavor = data.get(\"flavor\", \"compose\")\n        return flask.Response(\n            render_flavor(flavor, filepath, data),\n            mimetype=\"application/text\"\n        )\n\n    app.register_blueprint(bp, url_prefix=\"/{}\".format(version))\n\n\nif __name__ == \"__main__\":\n    build_app(\"/tmp/mailutest\")\n    app.run(debug=True)\n", "path": "setup/server.py"}], "after_files": [{"content": "import flask\nimport flask_bootstrap\nimport redis\nimport json\nimport os\nimport jinja2\nimport uuid\nimport string\nimport random\nimport ipaddress\n\n\nversion = os.getenv(\"this_version\")\nstatic_url_path = \"/\" + version + \"/static\"\napp = flask.Flask(__name__, static_url_path=static_url_path)\nflask_bootstrap.Bootstrap(app)\ndb = redis.StrictRedis(host='redis', port=6379, db=0)\n\n\ndef render_flavor(flavor, template, data):\n    return flask.render_template(\n        os.path.join(flavor, template),\n        **data\n    )\n\n\n@app.add_template_global\ndef secret(length=16):\n    charset = string.ascii_uppercase + string.digits\n    return ''.join(\n        random.SystemRandom().choice(charset)\n        for _ in range(length)\n    )\n\n\ndef build_app(path):\n\n    app.jinja_env.trim_blocks = True\n    app.jinja_env.lstrip_blocks = True\n\n    @app.context_processor\n    def app_context():\n        return dict(versions=os.getenv(\"VERSIONS\",\"master\").split(','))\n\n    prefix_bp = flask.Blueprint(version, __name__)\n    prefix_bp.jinja_loader = jinja2.ChoiceLoader([\n        jinja2.FileSystemLoader(os.path.join(path, \"templates\")),\n        jinja2.FileSystemLoader(os.path.join(path, \"flavors\"))\n    ])\n\n    root_bp = flask.Blueprint(\"root\", __name__)\n    root_bp.jinja_loader = jinja2.ChoiceLoader([\n        jinja2.FileSystemLoader(os.path.join(path, \"templates\")),\n        jinja2.FileSystemLoader(os.path.join(path, \"flavors\"))\n    ])\n\n    @prefix_bp.context_processor\n    @root_bp.context_processor\n    def bp_context(version=version):\n        return dict(version=version)\n\n    @prefix_bp.route(\"/\")\n    @root_bp.route(\"/\")\n    def wizard():\n        return flask.render_template('wizard.html')\n\n    @prefix_bp.route(\"/submit_flavor\", methods=[\"POST\"])\n    @root_bp.route(\"/submit_flavor\", methods=[\"POST\"])\n    def submit_flavor():\n        data = flask.request.form.copy()\n        steps = sorted(os.listdir(os.path.join(path, \"templates\", \"steps\", data[\"flavor\"])))\n        return flask.render_template('wizard.html', flavor=data[\"flavor\"], steps=steps)\n\n    @prefix_bp.route(\"/submit\", methods=[\"POST\"])\n    @root_bp.route(\"/submit\", methods=[\"POST\"])\n    def submit():\n        data = flask.request.form.copy()\n        data['uid'] = str(uuid.uuid4())\n        data['dns'] = str(ipaddress.IPv4Network(data['subnet'])[-2])\n        db.set(data['uid'], json.dumps(data))\n        return flask.redirect(flask.url_for('.setup', uid=data['uid']))\n\n    @prefix_bp.route(\"/setup/<uid>\", methods=[\"GET\"])\n    @root_bp.route(\"/setup/<uid>\", methods=[\"GET\"])\n    def setup(uid):\n        data = json.loads(db.get(uid))\n        flavor = data.get(\"flavor\", \"compose\")\n        rendered = render_flavor(flavor, \"setup.html\", data)\n        return flask.render_template(\"setup.html\", contents=rendered)\n\n    @prefix_bp.route(\"/file/<uid>/<filepath>\", methods=[\"GET\"])\n    @root_bp.route(\"/file/<uid>/<filepath>\", methods=[\"GET\"])\n    def file(uid, filepath):\n        data = json.loads(db.get(uid))\n        flavor = data.get(\"flavor\", \"compose\")\n        return flask.Response(\n            render_flavor(flavor, filepath, data),\n            mimetype=\"application/text\"\n        )\n\n    app.register_blueprint(prefix_bp, url_prefix=\"/{}\".format(version))\n    app.register_blueprint(root_bp)\n\n\nif __name__ == \"__main__\":\n    build_app(\"/tmp/mailutest\")\n    app.run(debug=True)\n", "path": "setup/server.py"}]}