From 6d6a443c898c60655bcee274ebee4f1714163658 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Wed, 2 Jul 2025 15:55:50 +1000 Subject: [PATCH] feat: Add some readme info and add some more boilerplate code --- README.md | 20 +++++++++++++++-- server.py | 29 +++++++++++++++++++++++- templates/assets/css/index.css | 21 +++++++++++++++++ templates/index.html | 41 ++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2f77bf4..9206f25 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,19 @@ -# python-webserver-template +# Python Flask Webserver Template -Python3 website template including git actions \ No newline at end of file +Python3 website template including git actions + +# Development +1. Install requirements +```bash +python3 -m pip install -r requirements.txt +``` +2. Run the dev server +```bash +python3 server.py +``` + +# Production +Run using the main.py file +```bash +python3 main.py +``` \ No newline at end of file diff --git a/server.py b/server.py index 240a1a8..d413b84 100644 --- a/server.py +++ b/server.py @@ -74,7 +74,9 @@ def wellknown(path): # region Main routes @app.route("/") def index(): - return render_template("index.html") + # Get current time in the format "dd MMM YYYY hh:mm AM/PM" + current_datetime = datetime.now().strftime("%d %b %Y %I:%M %p") + return render_template("index.html", datetime=current_datetime) @app.route("/") @@ -102,6 +104,31 @@ def catch_all(path: str): # endregion +# region API routes + +api_requests = 0 + +@app.route("/api/v1/data", methods=["GET"]) +def api_data(): + """ + Example API endpoint that returns some data. + You can modify this to return whatever data you need. + """ + + global api_requests + api_requests += 1 + + data = { + "header": "Sample API Response", + "content": f"Hello, this is a sample API response! You have called this endpoint {api_requests} times.", + "timestamp": datetime.now().isoformat(), + } + return jsonify(data) + + +# endregion + + # region Error Catching # 404 catch all @app.errorhandler(404) diff --git a/templates/assets/css/index.css b/templates/assets/css/index.css index 9635f9c..3ef53b7 100644 --- a/templates/assets/css/index.css +++ b/templates/assets/css/index.css @@ -17,4 +17,25 @@ a { } a:hover { text-decoration: underline; +} + +/* Mike section styling */ +.mike-section { + margin-top: 30px; + max-width: 600px; + margin-left: auto; + margin-right: auto; + padding: 20px; + background-color: rgba(50, 50, 50, 0.3); + border-radius: 8px; +} + +.mike-section h2 { + color: #f0f0f0; + margin-top: 0; +} + +.mike-section p { + line-height: 1.6; + margin-bottom: 15px; } \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index bb349f8..f3aac2c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -13,7 +13,48 @@

Nathan.Woodburn/

+ The current date and time is {{datetime}}
+ +
+
+

Pulling data

+ This is a test content area that will be updated with data from the server. +
+
+ +
+ + + \ No newline at end of file