simple form to update message text

This commit is contained in:
2021-05-18 19:32:59 +02:00
parent 6f291aa47a
commit d548ce044a
2 changed files with 24 additions and 6 deletions

View File

@@ -1,9 +1,17 @@
from autoreply_editor import app from autoreply_editor import app
from flask import render_template from flask import Flask, request, render_template, redirect
@app.route("/") @app.route("/")
def index(): def index():
with open(app.config.get("MESSAGE_FILE"), "r") as f: with open(app.config.get("MESSAGE_FILE"), "r") as f:
content = f.read() message = f.read()
return render_template("index.html", content=content) return render_template("index.html", message=message)
@app.route('/', methods=['POST'])
def index_post():
input_message = request.form['message'] + '\n'
if request.method == 'POST':
with open(app.config.get("MESSAGE_FILE"), 'w') as f:
f.write(str(input_message))
return redirect("/")

View File

@@ -1,3 +1,13 @@
<p> <!DOCTYPE html>
Hello! {{ content }} <head>
</p> <title>Autoreply Editor</title>
</head>
<body>
<form action="" method="POST">
<textarea name="message" cols="70" rows="10">{{ message }}</textarea>
<br />
<input type="submit" value="Update">
</form>
</body>
</html>