I am currently trying to have users upload photos to my webpage and then when they click submit, have those photos go to a folder in my directory. I keep getting the error in my error.log: 2019-12-02 20:18:35,954: "The view function did not return a valid response. The" Has anyone got this error before? I have tried everything but I am unable to fix this issue!
Python Code:
from flask import Flask, flash, redirect, render_template, request, url_for, send_from_directory
from werkzeug.utils import secure_filename
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = '/home/HassanSherien/mysite/Shape_Image/'
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
#@app.route('/upload', methods=['GET', 'POST'])
@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit a empty part without filename
if file.filename == '':
flash('No selected file')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
flash(file)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return redirect(url_for('uploaded_file',filename=filename))
#elif request.method == "GET":
#return render_template("overview_main_page.html", comments=Comment.query.all())
#return
@app.route('/uploads/<filename>', methods=["GET", "POST"])
def uploaded_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'],
filename)
<!-- Html Code Below -->
<div class="w3-panel">
<div class="w3-row-padding" style="margin:0 -16px">
<div class="w3-third">
<form action="{{ url_for('upload_file') }}" method="post">
<!-- <form action="{{ url_for('upload_file') }}" method='POST'> -->
<input type="file" name="file" value="fileupload" id="file_upload">
<input type='submit' />