for now have the home page redirect to the lookup page and do not use Blueprint (trying to keep the site single page
This commit is contained in:
parent
486c855e18
commit
4133fe3811
@ -1,6 +1,8 @@
|
||||
import os
|
||||
from flask import Flask, redirect, url_for, render_template
|
||||
from flask import Flask, redirect, url_for, render_template, request, flash
|
||||
from .src import host_lookup
|
||||
from dotenv import load_dotenv
|
||||
from markupsafe import escape
|
||||
|
||||
# Instead of turning 'lookup' into a Blueprint, maybe I could make a history of previous lookups a Blueprint?
|
||||
|
||||
@ -23,10 +25,31 @@ def create_app(test_config=None):
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
return render_template("index.html")
|
||||
# return render_template("index.html")
|
||||
return redirect(url_for("lookup"))
|
||||
|
||||
from . import lookup
|
||||
@app.route("/lookup", methods=(["GET", "POST"]))
|
||||
def lookup():
|
||||
hosts = []
|
||||
results = []
|
||||
if request.method == "GET":
|
||||
return render_template("lookup.html")
|
||||
elif request.method == "POST" and any(request.form.get("host")):
|
||||
print(f'REQUEST.FORM.GET("HOST") IS {request.form.get("host")}')
|
||||
user_input = escape(request.form.get("host").strip())
|
||||
hosts, errors = host_lookup.process_input(user_input)
|
||||
for host in hosts:
|
||||
result = host_lookup.Lookedup(host)
|
||||
results.append(result)
|
||||
return render_template("results.html", hosts=results, errors=errors)
|
||||
else:
|
||||
flash("Nothing entered! Try again?", "error")
|
||||
return render_template("lookup.html")
|
||||
|
||||
app.register_blueprint(lookup.bp)
|
||||
def lookup():
|
||||
hosts = []
|
||||
|
||||
# from . import lookup
|
||||
# app.register_blueprint(lookup.bp)
|
||||
|
||||
return app
|
||||
|
Loading…
x
Reference in New Issue
Block a user