Populate html drop-down using data from postgresql database using Python-Flask Populate html drop-down using data from postgresql database using Python-Flask flask flask

Populate html drop-down using data from postgresql database using Python-Flask


It seems like you need to read Flask's Quickstart to learn some basic.

Here is a minimal application that meets your needs.

View function:

from flask import Flask, render_templateapp = Flask(__name__)@app.route('/')def index():    items = get_your_data_from_db()    return render_template('index.html', items=items)

templates/index.html

<html>  <head>  </head><body><form><select multiple="multiple">{% for item in items %}<option value="{{ item.field_name }}">{{ item.field_name }}</option>{% endfor %}</select></form></body></html>