Sep-24-2018, 04:23 PM
You need to save it somewhere first. If it isn't that important to you, you can store it in memory and make it a global variable, and then pass it to the template like how was shown earlier with the
Something like this:
location
parameter.Something like this:
from flask import Flask, render_template, jsonify from apscheduler.schedulers.background import BackgroundScheduler import random import requests app = Flask(__name__) content = None def parse_func(): global content response = requests.get('https://nghttp2.org/httpbin/get') r = response.json() lst = [r['url'], r['origin']] rand_value = random.choice(lst) content = rand_value @app.route("/") def template(): global content return render_template('sh2.html', location=content) if __name__ == '__main__': scheduler = BackgroundScheduler() scheduler.add_job(parse_func, 'interval', seconds=15) scheduler.start() app.run(debug=True)