updated with app.py with new features

main
chae 2 years ago
parent 7120061589
commit 3d1950f4f1

@ -1,4 +1,5 @@
from flask import Flask, redirect, url_for, request, render_template
import uuid
# Create the application.
APP = Flask(__name__)
@ -11,8 +12,13 @@ def drawPlz():
name = request.form.get('lostobject')
msg = "Sorry that you lost {name}. But {name} will be having fun somewhere."
if request.method == 'POST':
args =request.args
print(args.get("msg"))
id = args.get("id")
image = request.form["data"]
print(image)
with open('database/'+ str(id) +'.txt', 'a+') as db:
db.write(f"{ image }")
return render_template("drawing.html", title=title, msg=msg)
@APP.route('/', methods=['GET', 'POST'])
@ -23,7 +29,8 @@ def index():
# If something is submitted through the form...
# ref: https://pythonbasics.org/flask-http-methods/
if request.method == 'POST':
id = uuid.uuid4()
print(id)
# Read the values from the form element.
name = request.form.get('lostobject', 'nana')
text = request.form.get('text', 'haha')
@ -37,12 +44,12 @@ def index():
# Note that the file is opened in the mode "a+"
# which means that the Flask application will append values
# (and not overwrite the csv file).
with open('database.csv', 'a+') as db:
db.write(f"{ name } | { text } \n")
with open('database/'+ str(id) +'.txt', 'w') as db:
db.write(f"{ name } \n{ text } \n")
msg = "Thanks!"
# return render_template('index.html', title=title, msg=msg)
return redirect(url_for('drawPlz', title=title, msg=msg))
return redirect(url_for('drawPlz', title=title, msg=msg, id=id))
# If the index page is loaded...
msg = "Please submite the form below."

Loading…
Cancel
Save