Is there a way to take user input from HTML, and use python to run the input through to a SQL database? Does the input need to be parsed? I want the the user to be able to type in a store name, and for it to return relevant rows
def search():
store_search = request.form.get("store")
if request.method == "POST":
if not store_search:
return "please type in a store!"
else:
c = conn.cursor()
c.execute("SELECT * FROM stores WHERE store_name= 'store_search'")
rows = c.fetchall()
for eachRow in rows:
return row
else:
return render_template("search.html")
HTML:
{% extends "main_page.html" %}
{% block title %}
Search
{% endblock %}
{% block main %}
<form action="{{ url_for('search') }}" method="post">
<fieldset>
<div class="form-group">
<input autocomplete="off" autofocus class="form-control"
name="store" placeholder="store" type="text"/>
</div>
<div class="form-group">
<button class="btn btn-default" type="submit">search</button>
</div>
<div class="page-header">
<h1>{{ store }}</h1>
</div>
</fieldset>
</form>
{% endblock %}