Skip to content

Instantly share code, notes, and snippets.

@bmorphism
Created April 24, 2023 18:38
Show Gist options
  • Save bmorphism/4438e5e050301ef3cd2227aa770fa1f9 to your computer and use it in GitHub Desktop.
Save bmorphism/4438e5e050301ef3cd2227aa770fa1f9 to your computer and use it in GitHub Desktop.
upload_form.py
from flask import Flask, render_template, request
from flask_wtf import FlaskForm
from werkzeug.utils import secure_filename
app = Flask(__name__)
app.config['SECRET_KEY'] = 'your-secret-key'
app.config['UPLOAD_FOLDER'] = 'uploads/'
class UploadForm(FlaskForm):
pass
@app.route('/', methods=['GET', 'POST'])
def upload_file():
form = UploadForm()
if request.method == 'POST':
file = request.files.get('file')
if file:
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return f"File uploaded and saved as {filename}"
return render_template('upload.html', form=form)
if __name__ == '__main__':
app.run(debug=True, host=0.0.0.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment