|
|
@ -14,11 +14,18 @@ ALLOWED_FILES = ["jpg", "png", "gif", "webp"] |
|
|
|
# don't config these lines |
|
|
|
APP.config["SECRET_KEY"] = os.urandom(24) |
|
|
|
|
|
|
|
|
|
|
|
class ImageUploadForm(FlaskForm): |
|
|
|
"""Image upload form.""" |
|
|
|
|
|
|
|
image = FileField( |
|
|
|
"image:", |
|
|
|
validators=[FileAllowed(ALLOWED_FILES, f"Images only, please use any of the following file extensions: {(", ").join(ALLOWED_FILES)}")], |
|
|
|
validators=[ |
|
|
|
FileAllowed( |
|
|
|
ALLOWED_FILES, |
|
|
|
f"Images only, please use any of the following file extensions: {(", ").join(ALLOWED_FILES)}", |
|
|
|
) |
|
|
|
], |
|
|
|
) |
|
|
|
submit = SubmitField("Submit") |
|
|
|
|
|
|
@ -32,10 +39,22 @@ def saveimage(image): |
|
|
|
def index(): |
|
|
|
"""Upload route, a page to upload an image""" |
|
|
|
imageuploadform = ImageUploadForm() |
|
|
|
uploaded_files = sorted( |
|
|
|
[ |
|
|
|
os.path.join(APP.config["IMAGE_FOLDER"], file) |
|
|
|
for file in os.listdir(APP.config["IMAGE_FOLDER"]) |
|
|
|
], |
|
|
|
key=os.path.getctime, |
|
|
|
) |
|
|
|
print(uploaded_files) |
|
|
|
if request.method == "POST": |
|
|
|
if imageuploadform.validate_on_submit(): |
|
|
|
saveimage(imageuploadform.image.data) |
|
|
|
return render_template("upload.html", imageuploadform=imageuploadform) |
|
|
|
return render_template( |
|
|
|
"upload.html", |
|
|
|
imageuploadform=imageuploadform, |
|
|
|
uploaded_files=uploaded_files |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|