S
S
shell_guy2021-12-17 19:30:30
Flask
shell_guy, 2021-12-17 19:30:30

How to pull data from a .txt file into a dropdown form?

I want to create a web form using flask, js and html:

61bcba6a0cfbd144175238.png

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <title>Python Flask Dynamic Select Box using Flask, JS and txt </title>

</h2></p>
<pre> 
{{ text }} 
</pre> 

</body>
</html>


form.py

from flask import Flask, render_template 
 
app = Flask(__name__) 
 
@app.route('/') 
def index(): 
  with open('QA.txt', 'r', encoding = 'utf-8') as f: 
    return render_template('index.html',  text=f.read())

PS Looked at the source code here.
I'm trying to do the same, only without a database, but from a file. What should be added to the code?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question