-1

I am writing a Flask app. I created a dropdown menu (list is produced by an external function called get_ligand_list here):

@app.route('/displayLigands', methods=['GET','POST'])
def dropdown():
    file = os.path.join(UPLOAD_FOLDER)
    molfile = UPLOAD_FOLDER + session.get('str_file', None)
    ligands = get_ligand_list(molfile)

    return render_template('run_ligand.html', ligands=ligands)

And corresponding HTML:

<form name="Item_1" action="{{ url_for('displayLigands') }}" method='POST'>
            <label for="exampleFormControlFile2">Choose ligand</label>
            <select name=ligands>
                {% for ligand in ligands %}
                    <option value="{{ligand}}">{{ligand}}</option>
                {% endfor %}     
            </select>
            <a class="btn btn-outline-primary btn-lg button-custom button-submit" type="submit" value="submit" href="{{ url_for('display_3dmol') }}">Next</a>
</form>

Everything is okay, the list is displayed.

How can I now retrieve the value from the list selected by the user?

Thank you!

Jagoda
  • 424
  • 1
  • 5
  • 18

1 Answers1

1

It seems like you’re trying to retrieve the submitted form data.

You can do so by using flask request.

ligand = request.form[‘ligands’]

note that ‘ligands’ is the name that you have given to form input field.

Don’t forget to import request using

from flask import request
Abbas
  • 623
  • 4
  • 6