From d7532b71345763534bc919b64c55d4fb04fbcbc1 Mon Sep 17 00:00:00 2001 From: abhiramtx <7253115-abhiramtx@users.noreply.replit.com> Date: Sat, 13 Dec 2025 21:43:34 +0000 Subject: [PATCH] Improve image loading by handling different storage paths Add a custom Jinja filter `image_url` to `app.py` to correctly resolve image paths from object storage or local static files, and update all relevant templates (members, sponsors, competitions, contributors) to use this new filter instead of the `url_for('static', filename=...)` function, ensuring images are displayed correctly regardless of their storage location. Replit-Commit-Author: Agent Replit-Commit-Session-Id: cd9a7d26-a4e5-4215-975c-c59f4ed1f06d Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: a02b1418-2e19-496d-9921-3a4afe97ac0d Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/d0a1d46d-d203-4308-bc6a-312ac7c0243b/cd9a7d26-a4e5-4215-975c-c59f4ed1f06d/05bPjFc --- app.py | 9 +++++++++ templates/admin/members.html | 4 ++-- templates/admin/sponsors.html | 2 +- templates/competitions.html | 2 +- templates/contributors.html | 4 ++-- templates/sponsors.html | 2 +- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index bdfc9e4..af5e82d 100644 --- a/app.py +++ b/app.py @@ -32,6 +32,15 @@ def get_db_connection(): conn = psycopg2.connect(os.environ['DATABASE_URL']) return conn +@app.template_filter('image_url') +def image_url_filter(path): + """Convert image path to proper URL - handles both storage and local paths""" + if not path: + return url_for('static', filename='images/default.jpg') + if path.startswith('/storage/'): + return path + return url_for('static', filename=path) + def upload_file_to_storage(file, folder='uploads'): """ Upload file to object storage if available, otherwise fall back to local storage diff --git a/templates/admin/members.html b/templates/admin/members.html index 9717cd3..70feb4a 100644 --- a/templates/admin/members.html +++ b/templates/admin/members.html @@ -186,7 +186,7 @@
{{ mentor.role }}
@@ -205,7 +205,7 @@{{ member.role }}
diff --git a/templates/admin/sponsors.html b/templates/admin/sponsors.html index c7999ac..2db3bea 100644 --- a/templates/admin/sponsors.html +++ b/templates/admin/sponsors.html @@ -146,7 +146,7 @@ {% for sponsor in sponsors %}{{ mentor.role }}
@@ -63,7 +63,7 @@ {% for member in members %}{{ member.role }}
diff --git a/templates/sponsors.html b/templates/sponsors.html index c85ade1..ba8df56 100644 --- a/templates/sponsors.html +++ b/templates/sponsors.html @@ -16,7 +16,7 @@ {% for sponsor in sponsors %}