-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.py
30 lines (20 loc) · 822 Bytes
/
search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from flask import Flask, render_template, request, redirect, url_for
from search_engine import search_query
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
"""Render the index.html template for the home page."""
return render_template('index.html')
@app.route('/result', methods=['GET', 'POST'])
def result():
"""Handle the form submission and display search results."""
if request.method == 'POST':
query = request.form.get('query')
if query:
print(f"Received query: {query}")
results = search_query(query)
return render_template('result.html', query=query, results=results)
print("Invalid request - Missing or invalid form data")
return "Invalid request"
if __name__ == '__main__':
app.run(debug=True)