added about page

learned about updating values with set interval
This commit is contained in:
Nico Melone
2025-01-22 08:35:46 -06:00
parent 1222be277d
commit 674f30cbd8
6 changed files with 33 additions and 0 deletions

BIN
.DS_Store vendored

Binary file not shown.

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.DS_Store

4
app.py
View File

@@ -1,5 +1,6 @@
from flask import Flask, render_template, request, redirect, url_for from flask import Flask, render_template, request, redirect, url_for
from models import db, Item from models import db, Item
from datetime import datetime as dt
app = Flask(__name__) app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///items.db' app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///items.db'
@@ -32,5 +33,8 @@ def add_item():
return redirect(url_for('home')) return redirect(url_for('home'))
return render_template('add_item.html') return render_template('add_item.html')
@app.route('/about')
def about():
return render_template('about.html', now=dt.now())
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=True) app.run(debug=True)

Binary file not shown.

26
templates/about.html Normal file
View File

@@ -0,0 +1,26 @@
{% extends "base.html" %}
{% block content %}
<h1 id="datetime" data-time="{{now.isoformat()}}">{{now.isoformat()}}</h1>
<script>
// JavaScript to update the datetime dynamically
function updateTime() {
const dateElement = document.getElementById('datetime');
const currentTime = new Date(dateElement.dataset.time);
// Increment the datetime by 1 second
currentTime.setSeconds(currentTime.getSeconds() + 1);
// Format the datetime as a readable string
const formattedTime = currentTime.toLocaleString();
// Update the displayed datetime
dateElement.textContent = formattedTime;
// Update the data-time attribute for the next update
dateElement.dataset.time = currentTime.toISOString();
}
// Update the datetime every second
setInterval(updateTime, 1000);
</script>
{% endblock %}

View File

@@ -11,6 +11,7 @@
<nav> <nav>
<a href="{{ url_for('home') }}">Home</a> <a href="{{ url_for('home') }}">Home</a>
<a href="{{ url_for('add_item') }}">Add Item</a> <a href="{{ url_for('add_item') }}">Add Item</a>
<a href="{{ url_for('about') }}">About</a>
</nav> </nav>
</header> </header>
<main> <main>