I am attempting to create code that allows users to input a photo and have that photo save to the folder '/home/HassanSherien/mysite/Shape_Image'. I have followed the steps given in the below link but I keep getting an error that states "Not Found, the requested URL was not found on the serves. if you entered the URL manually, please check your spelling and try again."
Python:
import os
from flask import Flask, request, redirect, url_for
from werkzeug.utils import secure_filename
UPLOAD_FOLDER = '/home/HassanSherien/mysite/Shape_Image'
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
def upload_file():
if request.method == 'POST':
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
if file.filename == '':
flash('No selected file')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
HTML:
<form action="myform.cgi">
<input type="file" name="fileupload" value="fileupload"
id="file`upload">
<label for="fileupload"> Select a file to upload</label>
<br>
<input type="image" src="/wp-content/uploads/sendform.png"
alt="Submit" width="100">
</form>
I am also given an error on the line if file and allowed_file(file.filename): that says "undefined name 'allowed_file'"