1

Is it possible to get the value inside <div> aside from <input> in Flask through request.args.get?. For example, <div id="time"> then in the backend request.args.get('time'). My purpose for this is that I don't want to expose the time parameter and its value inside the url after the user hit the submit button.

<!DOCTYPE html>
<html lang="en">
<html>
  <body>
    <form>
      <div style="display:none;" id="time"></div>
      <input type="submit">
    </form>

    <script>
      document.getElementById("time").innerHTML = new Date();
    </script>
  </body>
</html>
0

1 Answer 1

4

Best approach is instead of div use hidden input field.

Javascript:

<!DOCTYPE html>
<html lang="en">
<html>
  <body>
    <form method="POST">
      <input type="hidden" name="time" id="time">
      <input type="submit">
    </form>

    <script>
      document.getElementById("time").value= new Date();
    </script>
  </body>
</html>

Then in python you can get the time value by request.

python:

request.form['time']
0