This question has been asked before, and I think I did what I saw, but I don’t know what I am doing wrong. I don't know much about jQuery, but I will do my best to explain what I'm trying to do.
I want to autofill based on a query from a database, so I have this in my template:
<script type="text/javascript"> $(function() { $( "#function_name" ).autocomplete({ source: '{{url_for("autocomplete")}}', minLength: 2, }); }); </script> <form id="function_search_form" method="post" action=""> {{form.function_name}} </form>
The form is generated by this Flask form class:
class SearchForm(Form): function_name = TextField('function_name', validators = [Required()])
And here is the autocomplete function:
@app.route('/autocomplete') def autocomplete(): results = [] search = request.args.get('term') results.append(db.session.query(Table.Name).filter(Table.Name.like('%' + search + '%')).all()) return dumps(results)
So jQuery should go to the autocomplete function and return the JSON back to autocomplete. At least I think what is happening. What am I doing wrong here?
jquery python flask autocomplete
miscsubbin
source share