nothing is showing on my webpage when i run my flask program

Im a new coder and i dont know why even though there are no errors, nothing is appearing on my web browser! I am currently trying to create a program which can iterate through different pdf files and find keywords

this is all my code

search.py

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import fitz # PyMuPDF
import os
class PDFSearcher:
def __init__(self, upload_folder):
self.upload_folder = upload_folder
self.allowed_extensions = {'pdf'}
def allowed_file(self, filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in self.allowed_extensions
def search_keyword_in_pdf(self, file_path, keyword):
doc = fitz.open(file_path)
results = []
for page_num in range(len(doc)):
page = doc.load_page(page_num)
text = page.get_text()
if keyword.lower() in text.lower():
results.append((page_num + 1, text))
return results
def save_file(self, file):
filename = os.path.join(self.upload_folder, file.filename)
file.save(filename)
return filename
</code>
<code>import fitz # PyMuPDF import os class PDFSearcher: def __init__(self, upload_folder): self.upload_folder = upload_folder self.allowed_extensions = {'pdf'} def allowed_file(self, filename): return '.' in filename and filename.rsplit('.', 1)[1].lower() in self.allowed_extensions def search_keyword_in_pdf(self, file_path, keyword): doc = fitz.open(file_path) results = [] for page_num in range(len(doc)): page = doc.load_page(page_num) text = page.get_text() if keyword.lower() in text.lower(): results.append((page_num + 1, text)) return results def save_file(self, file): filename = os.path.join(self.upload_folder, file.filename) file.save(filename) return filename </code>
import fitz  # PyMuPDF
import os

class PDFSearcher:
    def __init__(self, upload_folder):
        self.upload_folder = upload_folder
        self.allowed_extensions = {'pdf'}

    def allowed_file(self, filename):
        return '.' in filename and filename.rsplit('.', 1)[1].lower() in self.allowed_extensions

    def search_keyword_in_pdf(self, file_path, keyword):
        doc = fitz.open(file_path)
        results = []
        for page_num in range(len(doc)):
            page = doc.load_page(page_num)
            text = page.get_text()
            if keyword.lower() in text.lower():
                results.append((page_num + 1, text))
        return results

    def save_file(self, file):
        filename = os.path.join(self.upload_folder, file.filename)
        file.save(filename)
        return filename

index.html

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PDF Search</title>
</head>
<body>
<h1>Search in PDF Files</h1>
<form method="POST" enctype="multipart/form-data">
<label for="keyword">Keyword:</label>
<input type="text" id="keyword" name="keyword" required>
<br><br>
<label for="files">Select PDF files:</label>
<input type="file" id="files" name="files" multiple required>
<br><br>
<input type="submit" value="Search">
</form>
{% if keyword %}
<h2>Search Results for "{{ keyword }}"</h2>
{% for filename, results in search_results %}
<h3>{{ filename }}</h3>
{% for page_num, text in results %}
<h4>Page {{ page_num }}</h4>
<p>{{ text }}</p>
{% endfor %}
{% endfor %}
{% endif %}
</body>
</html>
</code>
<code><!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>PDF Search</title> </head> <body> <h1>Search in PDF Files</h1> <form method="POST" enctype="multipart/form-data"> <label for="keyword">Keyword:</label> <input type="text" id="keyword" name="keyword" required> <br><br> <label for="files">Select PDF files:</label> <input type="file" id="files" name="files" multiple required> <br><br> <input type="submit" value="Search"> </form> {% if keyword %} <h2>Search Results for "{{ keyword }}"</h2> {% for filename, results in search_results %} <h3>{{ filename }}</h3> {% for page_num, text in results %} <h4>Page {{ page_num }}</h4> <p>{{ text }}</p> {% endfor %} {% endfor %} {% endif %} </body> </html> </code>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PDF Search</title>
</head>
<body>
    <h1>Search in PDF Files</h1>
    <form method="POST" enctype="multipart/form-data">
        <label for="keyword">Keyword:</label>
        <input type="text" id="keyword" name="keyword" required>
        <br><br>
        <label for="files">Select PDF files:</label>
        <input type="file" id="files" name="files" multiple required>
        <br><br>
        <input type="submit" value="Search">
    </form>

    {% if keyword %}
        <h2>Search Results for "{{ keyword }}"</h2>
        {% for filename, results in search_results %}
            <h3>{{ filename }}</h3>
            {% for page_num, text in results %}
                <h4>Page {{ page_num }}</h4>
                <p>{{ text }}</p>
            {% endfor %}
        {% endfor %}
    {% endif %}
</body>
</html>

app.py

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>from flask import Flask, request, render_template
import datetime
from pdf_search.search import PDFSearcher
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = 'uploads/'
pdf_searcher = PDFSearcher(app.config['UPLOAD_FOLDER'])
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
keyword = request.form['keyword']
files = request.files.getlist('files')
search_results = []
for file in files:
if file and pdf_searcher.allowed_file(file.filename):
filename = pdf_searcher.save_file(file)
results = pdf_searcher.search_keyword_in_pdf(filename, keyword)
if results:
search_results.append((file.filename, results))
return render_template('index.html', keyword=keyword, search_results=search_results)
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)
</code>
<code>from flask import Flask, request, render_template import datetime from pdf_search.search import PDFSearcher app = Flask(__name__) app.config['UPLOAD_FOLDER'] = 'uploads/' pdf_searcher = PDFSearcher(app.config['UPLOAD_FOLDER']) @app.route('/', methods=['GET', 'POST']) def index(): if request.method == 'POST': keyword = request.form['keyword'] files = request.files.getlist('files') search_results = [] for file in files: if file and pdf_searcher.allowed_file(file.filename): filename = pdf_searcher.save_file(file) results = pdf_searcher.search_keyword_in_pdf(filename, keyword) if results: search_results.append((file.filename, results)) return render_template('index.html', keyword=keyword, search_results=search_results) return render_template('index.html') if __name__ == '__main__': app.run(debug=True) </code>
from flask import Flask, request, render_template
import datetime
from pdf_search.search import PDFSearcher

app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = 'uploads/'

pdf_searcher = PDFSearcher(app.config['UPLOAD_FOLDER'])

@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'POST':
        keyword = request.form['keyword']
        files = request.files.getlist('files')
        search_results = []

        for file in files:
            if file and pdf_searcher.allowed_file(file.filename):
                filename = pdf_searcher.save_file(file)
                results = pdf_searcher.search_keyword_in_pdf(filename, keyword)
                if results:
                    search_results.append((file.filename, results))
        
        return render_template('index.html', keyword=keyword, search_results=search_results)
    
    return render_template('index.html')

if __name__ == '__main__':
    app.run(debug=True)

like

This is what my workspace looks like

and the only thing that appears when the program runs is a blank screen. Ive asked all the AIs and nothing can fix it!!please help me

what was expected to happen was that it would display the html

New contributor

briaNN is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật