list of files
This commit is contained in:
parent
9e888c1d59
commit
1548d03ef3
@ -8,18 +8,17 @@
|
|||||||
body {
|
body {
|
||||||
background-image: url({{ url_for('static', filename='content/glit_background.gif')}});
|
background-image: url({{ url_for('static', filename='content/glit_background.gif')}});
|
||||||
}
|
}
|
||||||
#uploadform{
|
.box {
|
||||||
background: #f9f871;
|
background: #f9f871;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
width: 30em;
|
width: 30em;
|
||||||
min-height: 5em;
|
min-height: 5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<form method="POST" enctype="multipart/form-data" id="uploadform">
|
<form method="POST" enctype="multipart/form-data" id="uploadform" class="box">
|
||||||
{{ imageuploadform.csrf_token }}
|
{{ imageuploadform.csrf_token }}
|
||||||
<fieldset class="fileupload-field">
|
<fieldset class="fileupload-field">
|
||||||
<legend>Upload an image here</legend>
|
<legend>Upload an image here</legend>
|
||||||
@ -31,4 +30,11 @@
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
{{ imageuploadform.submit }}
|
{{ imageuploadform.submit }}
|
||||||
</form>
|
</form>
|
||||||
|
<div class="box">
|
||||||
|
<ol>
|
||||||
|
{% for uploaded_file in uploaded_files %}
|
||||||
|
<li><a href="{{uploaded_file}}">{{uploaded_file}}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
23
upload.py
23
upload.py
@ -14,11 +14,18 @@ ALLOWED_FILES = ["jpg", "png", "gif", "webp"]
|
|||||||
# don't config these lines
|
# don't config these lines
|
||||||
APP.config["SECRET_KEY"] = os.urandom(24)
|
APP.config["SECRET_KEY"] = os.urandom(24)
|
||||||
|
|
||||||
|
|
||||||
class ImageUploadForm(FlaskForm):
|
class ImageUploadForm(FlaskForm):
|
||||||
"""Image upload form."""
|
"""Image upload form."""
|
||||||
|
|
||||||
image = FileField(
|
image = FileField(
|
||||||
"image:",
|
"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")
|
submit = SubmitField("Submit")
|
||||||
|
|
||||||
@ -32,10 +39,22 @@ def saveimage(image):
|
|||||||
def index():
|
def index():
|
||||||
"""Upload route, a page to upload an image"""
|
"""Upload route, a page to upload an image"""
|
||||||
imageuploadform = ImageUploadForm()
|
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 request.method == "POST":
|
||||||
if imageuploadform.validate_on_submit():
|
if imageuploadform.validate_on_submit():
|
||||||
saveimage(imageuploadform.image.data)
|
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__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user