fix: use dictionary to store the views and pass them to the jinja templates for easier access

Refs: OPS-11
This commit is contained in:
0xjrx 2025-02-25 14:48:25 +01:00
parent e134182974
commit 322d0684a1
3 changed files with 14 additions and 9 deletions

View file

@ -2,15 +2,20 @@ from flask import Flask, render_template
app = Flask(__name__)
urls = {
"home": "index_view",
"haiku":"haiku_view"
}
@app.route("/")
def index():
return render_template("index.jinja", title="Senju", active_page="home")
def index_view():
return render_template("index.jinja", title="Senju", urls=urls)
@app.route("/haiku")
def haiku_page():
def haiku_view():
return render_template(
"haiku.jinja",
title="Haiku of the Day",
active_page="haiku")
urls = urls)

View file

@ -25,16 +25,16 @@
<div class="hidden md:block">
<div class="ml-10 flex items-baseline space-x-4">
<!-- Current: "bg-gray-900 text-white", Default: "text-gray-300 hover:bg-gray-700 hover:text-white" -->
<a href="{{ url_for('index') }}"
<a href="{{ url_for(urls['home']) }}"
class="rounded-md px-3 py-2 text-sm font-medium
{% if request.endpoint == 'index' %} bg-gray-900 text-white {% else %} text-gray-300 hover:bg-gray-700 hover:text-white {% endif %}"
{% if request.endpoint == urls['home'] %} bg-gray-900 text-white {% else %} text-gray-300 hover:bg-gray-700 hover:text-white {% endif %}"
>
Start
</a>
<a href="{{ url_for('haiku_page') }}"
<a href="{{ url_for(urls['haiku']) }}"
class="rounded-md px-3 py-2 text-sm font-medium
{% if request.endpoint == 'haiku_page' %} bg-gray-900 text-white {% else %} text-gray-300 hover:bg-gray-700 hover:text-white {% endif %}"
{% if request.endpoint == urls['haiku'] %} bg-gray-900 text-white {% else %} text-gray-300 hover:bg-gray-700 hover:text-white {% endif %}"
>
Haiku
</a>

View file

@ -11,7 +11,7 @@
Splash! Silence again.
</p>
</div>
<a href="{{ url_for('index') }}" class=" inline-block bg-violet-600 hover:bg-violet-700 text-white font-bold py-2 px-4 rounded-lg">
<a href="{{ url_for(urls['home']) }}" class=" inline-block bg-violet-600 hover:bg-violet-700 text-white font-bold py-2 px-4 rounded-lg">
Back to Home
</a>
</div>