-1
@app.route("/home")
def get_response_data():
      number = userinput_from_form
      return render_tamplate('home.html', number=number)

@app.route("/home")
def post_response_data():
      value = number
      function_from_backend = aggregation(value)
      platform = aggregation.get_something()
      scoring = aggregation.do_something()
      return render_template('home.html', platform=platform, scoring=scoring)

My html looks like this using jinja2 templates:

    <table class="table">
        <thead>
          <tr>
            <th scope="col">#</th>
            <th scope="col">Score</th>
            <th scope="col">Platform</th>
            <th scope="col">Info</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th scope="row">{{ result }}</th>
            <td>{{ scoring }}</td>
            <td>{{ platform }}</td>
            <td>@asdfa</td>
          </tr>
          <tr>

What I am trying to achieve is get a user input and then populate a table with the values that another function I have built(aggregation), unrelated to flask, and get those values and "post" them in the table. I would Ideally like to not have the user switch pages just show the results directly on the same page.

My problem is I am not sure how to get the input from the user in the frontend and use it on the other function to return my desired result. I have tried using request.data, request.args.get('number') and sessions but I am stuck.

ItsJustMe
  • 19
  • 6

1 Answers1

1

It seems that you need to

  • display the table when you reach /home page, with a default value for number
  • display a specific a table related to the form number when you send a POST (validade a form) to /home
@app.route("/home", methods=['GET', 'POST'])
def get_response_data():
    number = 0  # default value

    if request.method == 'POST':
        number = userinput_from_form

    value = number
    function_from_backend = aggregation(value)
    platform = aggregation.get_something()
    scoring = aggregation.do_something()
    return render_template('home.html', platform=platform, scoring=scoring)
azro
  • 53,056
  • 7
  • 34
  • 70