I'm creating a Flask app, and in my tellmestory.html I have a form for users to select the age. In my app.py, I am trying to select the user's selected option but I always get None.
Here are some snippets of my code:
In my app.py I have this list and 2 routes:
AGE=[
"3", "4", "5", "6", "7", "8", "9", "10", "11", "12"
]
@app.route("/tellmestory")
def tellmestory():
return render_template("tellmestory.html", authors=AUTHORS, age=AGE, themes=THEMES)
@app.route("/story", methods=["POST"])
def story():
child_age = request.form.get("child_age")
return render_template("story.html", child_age=child_age)
In tellmestory.html I have this form:
<form action="/story" method="post">
<div class="form-group justify-content-center">
<label for="child_age">Select child's age:</label>
<select id="child_age" class="form-select" name="child_age" aria-label="Select child's age">
<option disabled selected>Select child's age</option>
{% for child_age in age%}
<option value="{{ child_age }}">{{ child_age }}</option>
{% endfor %}
</select>
</div>
</form>
In story.html I'm using Jinja to plug in the input:
<div class="container d-flex justify-content-center">
{{child_age}}
</div>
Is this code correct or am I missing something?(I'm a beginner)