Solution
from dataclasses import dataclass
from flask import request
# As an exception, since I cannot explain the use of a database to you in this
# example, I use a global variable. You shouldn't actually do this, but it is
# helpful in this case for the reason described above.
botlist = []
# For the same reason, I use a dataclass to map a model, which is later saved
# within the defined list.
@dataclass
class Bot:
username: str
channel: str
name: str
status: str
@app.route('/bots', methods=['GET', 'POST'])
def bots():
global botlist
if request.method == 'POST':
# If it is a POST request, create a bot object and append it to the list.
bot = Bot(
request.form['username'],
request.form['channel'],
request.form['name'],
request.form['status'],
)
botlist.append(bot)
# Re-render the page with the bots in the list.
return render_template('bots.html', botlist=botlist)
Bots
Username
Channel
Name
Status
{% for bot in botlist -%}
{{ bot.username }}
{{ bot.channel }}
{{ bot.name }}
{{ bot.status }}
{% endfor -%}