I have a file upload form in HTML, which should be used to upload and save to a static folder. The problem is that it works fine in a simple Flask app, but it just doesn't work using Blueprint templates.
I have tried several different ways of making this work. When I use "url_for", the page doesn't even load (werkzeug.routing.BuildError: Could not build url for endpoint 'upload'. Did you mean 'forms_blueprint.upload' instead?).
But when I change "url_for" to "form_upload.html", the result is always that the method is not allowed.
All thoughts are appreciated.
routes.py:
UPLOAD_FOLDER = '/home/juliosouto/flask-gentelella/app/uploaded_files/'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@blueprint.route('/<template>', methods = ['GET', 'POST'])
@login_required
def route_template(template):
return render_template('form_upload' + '.html')
@blueprint.route('/upload', methods=['POST','GET'])
def upload():
file = request.files['file']
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
form_upload.html:
<form action ="{{ url_for('upload') }}" class= "dropzone" name="file" method = "POST" enctype = "multipart/form-data"></form>
I need the file to be saved to a static folder.