simple navbar to switch between main lookup page that also includes results (but doesnt change routes)
This commit is contained in:
parent
dc3b11cf03
commit
bae53da357
@ -3,6 +3,7 @@ from flask import Flask, redirect, url_for, render_template, request, flash
|
|||||||
from .src import host_lookup
|
from .src import host_lookup
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from markupsafe import escape
|
from markupsafe import escape
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
# Instead of turning 'lookup' into a Blueprint, maybe I could make a history of previous lookups a Blueprint?
|
# Instead of turning 'lookup' into a Blueprint, maybe I could make a history of previous lookups a Blueprint?
|
||||||
|
|
||||||
@ -32,6 +33,8 @@ def create_app(test_config=None):
|
|||||||
def lookup():
|
def lookup():
|
||||||
hosts = []
|
hosts = []
|
||||||
results = []
|
results = []
|
||||||
|
errors_present = False
|
||||||
|
results_present = False
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
return render_template("lookup.html")
|
return render_template("lookup.html")
|
||||||
elif request.method == "POST" and any(request.form.get("host")):
|
elif request.method == "POST" and any(request.form.get("host")):
|
||||||
@ -41,15 +44,24 @@ def create_app(test_config=None):
|
|||||||
for host in hosts:
|
for host in hosts:
|
||||||
result = host_lookup.Lookedup(host)
|
result = host_lookup.Lookedup(host)
|
||||||
results.append(result)
|
results.append(result)
|
||||||
return render_template("results.html", hosts=results, errors=errors)
|
if any(results):
|
||||||
|
results_present = True
|
||||||
|
if any(errors):
|
||||||
|
errors_present = True
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
"results.html",
|
||||||
|
hosts=results,
|
||||||
|
errors=errors,
|
||||||
|
errors_present=errors_present,
|
||||||
|
results_present=results_present,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
flash("Nothing entered! Try again?", "error")
|
flash("Nothing entered! Try again?", "error")
|
||||||
return render_template("lookup.html")
|
return render_template("lookup.html")
|
||||||
|
|
||||||
def lookup():
|
@app.route("/history")
|
||||||
hosts = []
|
def history():
|
||||||
|
return render_template("history.html")
|
||||||
# from . import lookup
|
|
||||||
# app.register_blueprint(lookup.bp)
|
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
|
{% extends "layout.html" %}
|
||||||
|
|
||||||
<div class="test">
|
<div class="test">
|
||||||
|
|
||||||
<button type="button">History</button>
|
<button type="button">History</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
TESTING
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
{% include "navbar.html" %}
|
||||||
{% block content %} {% endblock %}
|
{% block content %} {% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,11 +8,10 @@
|
|||||||
</style>
|
</style>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<!--Continue from: https://dev.to/roccosangellino/how-to-build-a-simple-navbar-with-html-and-css-945-->
|
|
||||||
|
|
||||||
<nav class="navbar">
|
<nav class="navbar">
|
||||||
|
<!--Wound up going for a really simple navbar included in layout.html which as Jinja url_for-links to both functions. -->
|
||||||
<ul>
|
<ul>
|
||||||
<li><b><a href="#">Home</a></b></li>
|
<li><b><a href="{{url_for('lookup')}}">Home</a></b></li>
|
||||||
<li><b><a href="#">History</a></b></li>
|
<li><b><a href="{{url_for('history')}}">History</a></b></li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user