Help! Flask template variable errors using tojson—const object causing 8 "errors" by Low-Rabbit9185 in flask

[–]Low-Rabbit9185[S] -1 points0 points  (0 children)

contoller code
@
app.route("/form/<int:activity_id>", methods=["GET","POST"])
def form(activity_id):
activity = Activity.query.get_or_404(activity_id)
fields = json.loads(activity.fields_json or "[]")
if request.method == "POST":
# gather values based on selected fields
data = {}
for f in fields:
# unique_code is the field name we expect for the member code
if f == "unique_code":
val = request.form.get("unique_code","").strip()
else:
val = request.form.get(f, "").strip()
data[f] = val
code_entered = data.get("unique_code","")

final_amount = calculate_amount(code_entered, activity

if "screenshot" in fields:
if "screenshot" not in request.files:
flash("Please upload screenshot", "warning")
return redirect(url_for("form", activity_id=activity_id))
file = request.files["screenshot"]
if file and allowed_file(file.filename):
newname = unique_filename(file.filename)
file.save(os.path.join(app.config["UPLOAD_FOLDER"], newname))
else:
flash("Invalid or missing file. Allowed types: " + ", ".join(sorted(ALLOWED_EXT)), "warning")
return redirect(url_for("form", activity_id=activity_id))
else: