Here is my directory setup:
/output
/text_file.txt
/templates
/index.html
app.py
read.py
Here is my index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<div>
</div>
<button><a href="/abc"> Read</a></button>
</body>
</html>
Here is my app.py:
from flask import Flask, render_template, jsonify, redirect, request
import fitz
from read import read_txt
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/abc')
def link():
return read_txt("text_file.txt")
if __name__ == "__main__":
app.run(port=5000, debug = True)
and this is my read.py:
import os
def read_txt(file):
doc = os.getcwd()+"\\output\\"+file
with open(doc,"r") as f:
text = f.read()
return text
Question: I am reading a txt file in python. I want to make an html page with a button READ which when clicked will show me the content of txt file on the same page(same route path: http://127.0.0.1:5000/ ), inside that defined div component.
But for now, when I click on button, output is showing in another route (http://127.0.0.1:5000/abc).
I am really struggling with this. I read somewhere that we can use jinja template but I am not sure how to do this.
I am sorry if it is a very basic question but I am a begineer and unable to figure it out.
Thank you.