27 lines
640 B
Python
27 lines
640 B
Python
from flask import Flask, jsonify, render_template
|
|
from random import choice
|
|
import json
|
|
|
|
defaults = []
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route("/")
|
|
def index():
|
|
initial_word = choice(defaults)
|
|
return render_template("index.html", initial_word=initial_word["word"], initial_image_url=initial_word["image_url"])
|
|
|
|
@app.route("/random")
|
|
def random():
|
|
word = choice(defaults)
|
|
return jsonify(word=word["word"], image_url=word["image_url"])
|
|
|
|
@app.before_first_request
|
|
def load():
|
|
global defaults
|
|
file = open("startup.json")
|
|
defaults = json.load(file)
|
|
file.close()
|
|
|
|
if __name__ == "__main__":
|
|
app.run("0.0.0.0", 8000) |