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 dotenv import load_dotenv
|
||||
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?
|
||||
|
||||
@ -32,6 +33,8 @@ def create_app(test_config=None):
|
||||
def lookup():
|
||||
hosts = []
|
||||
results = []
|
||||
errors_present = False
|
||||
results_present = False
|
||||
if request.method == "GET":
|
||||
return render_template("lookup.html")
|
||||
elif request.method == "POST" and any(request.form.get("host")):
|
||||
@ -41,15 +44,24 @@ def create_app(test_config=None):
|
||||
for host in hosts:
|
||||
result = host_lookup.Lookedup(host)
|
||||
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:
|
||||
flash("Nothing entered! Try again?", "error")
|
||||
return render_template("lookup.html")
|
||||
|
||||
def lookup():
|
||||
hosts = []
|
||||
|
||||
# from . import lookup
|
||||
# app.register_blueprint(lookup.bp)
|
||||
@app.route("/history")
|
||||
def history():
|
||||
return render_template("history.html")
|
||||
|
||||
return app
|
||||
|
@ -1,4 +1,8 @@
|
||||
{% extends "layout.html" %}
|
||||
|
||||
<div class="test">
|
||||
|
||||
<button type="button">History</button>
|
||||
</div>
|
||||
|
||||
TESTING
|
||||
|
@ -21,6 +21,7 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{% include "navbar.html" %}
|
||||
{% block content %} {% endblock %}
|
||||
|
||||
|
||||
|
@ -8,11 +8,10 @@
|
||||
</style>
|
||||
-->
|
||||
|
||||
<!--Continue from: https://dev.to/roccosangellino/how-to-build-a-simple-navbar-with-html-and-css-945-->
|
||||
|
||||
<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>
|
||||
<li><b><a href="#">Home</a></b></li>
|
||||
<li><b><a href="#">History</a></b></li>
|
||||
<li><b><a href="{{url_for('lookup')}}">Home</a></b></li>
|
||||
<li><b><a href="{{url_for('history')}}">History</a></b></li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
Loading…
x
Reference in New Issue
Block a user