MTT
MTT

Reputation: 379

Datalist from python list

I am trying to generate a datalist on my website that comes from a list on python.

My html file is like this:

<!DOCTYPE html>
<html>
<body>

<form>
  <input list="hschools" name="hschool">
  <datalist id="hschools">
    {% for elem in hsch %}
        <option value= {{elem}}>
    {% endfor %}
  </datalist>
  <input type="submit">
</form>

</body>
</html>

And is saved in trying.html

My main.py file is:

from flask import Flask,render_template

app=Flask(__name__)

@app.route("/")
def index():
    hsch=["a","b","c"]
    return render_template("trying.html")

if __name__=="main":
    app.run()

I then try to run the web-app and I do not get anything. Can you see my error? Maybe I am not running it correctly... Thanks!

Upvotes: 0

Views: 1579

Answers (1)

G&#252;nther Jena
G&#252;nther Jena

Reputation: 3776

render_template needs hsch to be passed:

return render_template("trying.html", hsch=hsch)

Upvotes: 2

Related Questions