Show text or a value in the output box.
print("Hello")Web apps with Flask · In any playground, open Reference to copy these.
Show text or a value in the output box.
print("Hello")"w" makes the file, or empties it first if it is already there, then writes. with closes the file at the end.
with open("save.txt", "w") as f:
f.write(text)Each row of the file becomes a dictionary, keyed by the column names in the first line. Every value is text.
import csv
with open("music.csv") as f:
rows = list(csv.DictReader(f))Sends the browser on to another address, such as back home after a form.
return redirect("/")strip() removes spaces at the ends; lower() and upper() change the capitals. Each gives back new text.
command = command.strip().lower()Opens the file to read and gives you all of it as one piece of text.
with open("save.txt") as f:
text = f.read()A form with method='post' sends each box that has a name='...' attribute. request.form looks them up by that name.
@app.route("/join", methods=["POST"])
def join():
name = request.form["name"].strip()"a" adds to the end of the file instead of emptying it. Each list becomes one row.
with open("members.csv", "a", newline="") as f:
csv.writer(f).writerow([name, group])