You're seeing the errors that you are seeing because there is no data being passed from your form to the Flask server. Your use of request is returning a None value type as opposed to a str.
You posted the following HTML mark up for your form:
<form action="/student" method='POST'>
<select name="student_form ">
{% for student in students_list %}
<option value="{{student}}">{{student}}</option>
{% endfor %}
</select>
<input type='submit' value='submit' />
</form>
So therefore you're going to need somewhere for Flask to pick up this data on the server side, for example:
@app.route('/student', methods=['POST'])
def receive_student_form_data:
my_selection = str(request.form.get('student_form')).strip()
print(my_selection)
Just to clarify why I've made my method in this way: I notice that you're using request.args.get() in order to retrieve the value sent by the form. This is incorrect.
request.args is used to retrieve key / value pairs from the URL.
request.form is used to retrieve key / value pairs from a HTML form.
So I'd suggest that you should use request.form.get('student_form') instead. If you really want to be certain that it is being cast as a str when retrieved by your Flask server, then you can cast it as a str as follows:
str(request.form.get('student_form'))
Then, as has been suggested by a few people already, you can use the .strip() method to remove any trailing spaces.
request.args.get('student_form')returnedNone, not a string, because the fieldstudent_formis not there. You could return a default''instead withrequest.args.get('student_form', '')but you probably should check why the field is not there in the first place.<form action="student" method='POST'> <select name="student_form "> {% for student in students_list %} <option value="{{student}}">{{student}}</option> {% endfor %} </select> <input type='submit' value='submit'> </form>and here is .py:... with app.open_resource('static/docs/student3.txt') as f3: content3 = f3.read()...and:... elif (selected_student == students_list[3]): content_selected = content3 ...i delete smthing, i think its clear. and i'm not sure is there any blank character in form data...form action="student". Youractionshould be a URL and should read as/student. I assume you've set up your Flask server to include the route/student, then, too?