My application will be be pulling a query from a sample list eventually. For the time being I am trying to present the term entered into the HTML submit page onto the result HTML page. At the moment "queryterm" is not showing up on my result page. I have a feeling the term is not defined on the @app.route("/result")
which is why nothing is showing up. The variable is empty. How would I go about solving my issue? I am new to flask!
Python
from flask import Flask, render_template, request, url_for, redirect
from test_list import test_list
app = Flask(__name__)
@app.route("/")
def home_page():
return render_template('index.html')
@app.route("/submit", methods=["POST", "GET"])
def submit():
if request.method == "POST":
queryterm = request.form["search"]
return redirect(url_for("result", queryterm=queryterm))
else:
return render_template('submit.html')
@app.route("/result")
def result():
result = test_list
return render_template('result.html', result=result)
HTML Submit Page
{% block title %}Submit Page{% endblock %}
{% block content %}
<form action="#" method="post">
<p>Enter a search term</p>
<p><input type ="text" name="search" /></p>
<p><input type="submit" value="submit" /></p>
</form>
{% endblock %}
HTML Result Page
{% block title %}Result Page{% endblock %}
{% block content %}
<p>The query for {{ queryterm }} has found:</p>
<ul>
{% for item in result %}
<li>{{ item }}</li>
{% endfor %}
</ul>
{% endblock %}