The Problem:
I have an a input button in a form that when its submitted should redirect two parameters , search_val
and i
, to a more_results()
function, (listed below), but I get a type error when wsgi builds.
The error is: TypeError: more_results() takes exactly 2 arguments (1 given)
html:
<form action="{{ url_for('more_results', past_val=search_val, ind=i ) }}" method=post>
<input id='next_hutch' type=submit value="Get the next Hunch!" name='action'>
</form>
flask function:
@app.route('/results/more_<past_val>_hunches', methods=['POST'])
def more_results(past_val, ind):
if request.form["action"] == "Get the next Hunch!":
ind += 1
queried_resturants = hf.find_lunch(past_val) #method to generate a list
queried_resturants = queried_resturants[ind]
return render_template(
'show_entries.html',
queried_resturants=queried_resturants,
search_val=past_val,
i=ind
)
Any idea on how to get past the build error?
What I've tried:
Creating link to an url of Flask app in jinja2 template
for using multiple paramters with url_for()
Build error with variables and url_for in Flask
similar build erros
As side note, the purpose of the function is to iterate through a list when someone hits a "next page" button. I'm passing the variable i
so I can have a reference to keep incrementing through the list. Is there a flask / jinja 2 method that would work better? I've looked into the cycling_list feature but it doesn't seem to able to be used to render a page and then re-render it with cycling_list.next()
.