Let’s use our module now in our /poem route to create a new poem.
Within the function for our /poem route we’ll add the line to generate a poem and assign that string to the “poem” variable. Finally we’ll just return that poem string to the browser.
Here’s what our full app.py
looks like now:
# app.py
from flask import Flask, render_template, redirect, url_for, jsonify
import poembot
app = Flask(__name__)
@app.route('/')
def hello():
return "Hello world!"
@app.route('/poem')
def poem():
poem = poembot.generate_poem()
return poem
if __name__ == '__main__':
app.run(debug=True)
Now reload http://localhost:5000/poem to see a newly generated poem.
When you reload the page which fruit did you get? Paste it into chat or unmute to let us know.