2

I am working on this app, which has a form where you input the name, choose a value from a dropbox, and select one or more items from a checkbox. I need to redirect the values of this form to another page and format them to a table. I am new to programming, and want to get the values from the add form and format them into a table in the tally form. Here are my code snippets:

@app.route('/add', methods=['POST','GET'])
def add():
    if request.method == 'POST':
        plan_name = request.form
        formation_name = request.form
        variation_name = request.form
        return redirect('/tally')

    return render_template('add.html')
@app.route('/tally', methods=['Get','POST'])
def tally():


    return render_template('tally.html')



<form action='/add' method='POST'>
<h1>Enter a name for your gameplan:</h1>
  <div class="form-group row">
    <label for="plan" name = 'plan_name'value = '{{request.form['name']}}' class="col-sm-2 col-form-label">Name:</label>
    <div class="col-sm-10">
      <input type="text" >
    </div>
  </div>
<p><h1>Choose Your Formation<p></h1>
 <div class="form-row align-items-center">
    <div class="col-auto my-1">
      <select class="custom-select mr-sm-2" id="inlineFormCustomSelect">
        <option selected>Choose...</option>
        <option name = "formation_name" >Doubles</option>
      </select>
    </div>
  </div>

<p><h1>Select The Variation</h1></p>
 <div class="form-group row">
    <div class="col-sm-2">Select one or many:</div>
    <div class="col-sm-10">
      <div class="form-check">
        <input class="form-check-input" name = 'variation_name' type="checkbox" id="split">
        <label class="form-check-label" for="split">
          Split
        </label>
      </div>
      <div class="form-check">
        <input class="form-check-input" type="checkbox" id="nearPistol">
        <label class="form-check-label" for="nearPistol">
          Near Pistol
        </label>
      </div>
      <div class="form-check">
        <input class="form-check-input"  type="checkbox" id="farPistol">
        <label class="form-check-label" for="farPistol">
          Far Pistol
        </label>
      </div>
      <div class="form-check">
        <input class="form-check-input"   type="checkbox" id="queen">
        <label class="form-check-label" for="queen">
          Queen
        </label>
      </div>
      <div class="form-check">
        <input class="form-check-input"  type="checkbox" id="right">
        <label class="form-check-label" for="right">
          Right
        </label>
      </div>
      <div class="form-check">
        <input class="form-check-input"  type="checkbox" id="left">
        <label class="form-check-label" for="left">
          Left
        </label>
      </div>
    </div>
  </div>
  <div>
     <div class="form-group row">
    <div class="col-sm-10">
      <button type="submit" class="btn btn-primary">Save</button>
    </div>
  </div>
   <div class="form-group row">
    <div class="col-sm-10">
      <button type="submit" class="btn btn-primary">Add Another Formation</button>
    </div>
  </div>

  </div>

</form>


{%endblock%}


{%for key, values in add %}
  <thead >

    <tr>
      <th scope="col">{{key.formation_name}}</th>
      <th scope="col">Left</th>
      <th scope="col">Right</th>
    </tr>

  </thead>
  <tbody>


    <tr>
      <td scope="row">{{values.variation_name}}</td> 
         <td>
            <div class='container'>
                <button type="button" class="btn btn-outline-primary">Run</button>
                <button type="button" class="btn btn-outline-primary">Pass</button>
            </div>
        </td>
        <td>

            <div class='container'>
                <button type="button" class="btn btn-outline-primary">Run</button>
                <button type="button" class="btn btn-outline-primary">Pass</button>
            </div>
        </td>
    </tr>



  </tbody>
{% endfor %}

</table>
<div class="col-sm-10 container">
      <button type="submit" class="btn btn-primary">Tally Results</button>
</div>






{%endblock%}

1 Answer 1

1

Use redirect(url_for('/tally', key=key)) Where key is a dictionary of your variables formation_name and variation_name

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.