initial commit
This commit is contained in:
commit
124e327a6e
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
__pycache__
|
47
app.py
Normal file
47
app.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
import os
|
||||
from flask import Flask
|
||||
|
||||
from flask import request, render_template
|
||||
|
||||
app = Flask(
|
||||
__name__,
|
||||
# static_url_path="./",
|
||||
static_folder="static",
|
||||
template_folder="templates",
|
||||
)
|
||||
os.makedirs("uploads", exist_ok=True)
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def upload_form():
|
||||
return render_template(
|
||||
"upload.html",
|
||||
title="Upload your shit here",
|
||||
)
|
||||
|
||||
|
||||
@app.route("/upload", methods=["POST"])
|
||||
def upload_file():
|
||||
if "file" not in request.files:
|
||||
return "No file part"
|
||||
|
||||
file = request.files["file"]
|
||||
if file.filename == "":
|
||||
return "No selected file"
|
||||
|
||||
if not file:
|
||||
return "No file?"
|
||||
|
||||
save_path = os.path.join("uploads", file.filename)
|
||||
assert not os.path.exists(save_path)
|
||||
|
||||
try:
|
||||
file.save(save_path)
|
||||
except Exception as exc:
|
||||
return f"fail: {exc=}"
|
||||
|
||||
return "File uploaded successfully"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
flask
|
||||
gunicorn
|
10
templates/upload.html
Normal file
10
templates/upload.html
Normal file
|
@ -0,0 +1,10 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>{{ title }}</title>
|
||||
</head>
|
||||
|
||||
<form action="/upload" method="POST" enctype="multipart/form-data">
|
||||
<input type="file" name="file" />
|
||||
<button type="submit">Upload</button>
|
||||
</form>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user