How to give path of image from external JavaScript file in making Flask API?

Solution
import json

# ...
@app.route("/page")
def page():
  data = json.dumps({
    "uploadImageUrl": url_for("uploads", filename="image_name")
    # you can include other data
  })
  return render_template("page.html", data=data)

const data = JSON.parse(document.getElementById("data"));

// somewhere else in your code:
document.getElementById("uploadimg").setAttribute("src", data.uploadImageUrl);