Skip to content

Commit

Permalink
Create app context to render template
Browse files Browse the repository at this point in the history
  • Loading branch information
hammady committed May 18, 2024
1 parent b486139 commit 2c93395
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from flask import render_template
from flask import Flask, render_template
from qusasat import Qusasat
import base64

app = Flask(__name__)
# Load data
qusasat = Qusasat(categories_file='./data/categories.csv', quotes_file='./data/qusasat.csv')
# Load the only image we have as base64 data in memory
Expand All @@ -11,9 +12,10 @@
base64_string = base64_data.decode('utf-8')

def run(event, context):
global qusasat, base64_string
global app, qusasat, base64_string
quote = qusasat.get_random_quote()
return render_template('quote.html',
category=quote['category'],
quote=quote['quote'],
background_image_url=f'data:image/png;base64,{base64_string}')
with app.app_context():
return render_template('quote.html',
category=quote['category'],
quote=quote['quote'],
background_image_url=f'data:image/png;base64,{base64_string}')

0 comments on commit 2c93395

Please sign in to comment.