Flags redirection not working after boot

Basically I want to go to another page after loading. What is happening here is that the file downloads very quickly and is saved to the server, but after that the client (my browser) waits every hour and doesn't even redirect after waiting. If I remove it, I don't get the response as expected and everything happens within milliseconds.

@blah.route('/upload', methods=['GET', 'POST'])
def upload():
    if request.method == 'POST' and 'file' in request.files:
        file = request.files['file']
        if file:
            filename = secure_filename(file.filename)
            file.save(os.path.join('./tmp/uploads', filename))
            print '%s file saved' % filename

            return redirect(url_for("blah.list_uploads"))  
    return render_template('blah/upload.html')

      

enter image description here

Edit: Not sure if it helps to say I'm using DropzoneJS. I think it uses Ajax by default. Maybe there is something with this?

+4


source to share


3 answers


Update : You can now use Flask-Dropzone , a Flask extension that integrates Dropzone.js with Flask. For this problem, you can set DROPZONE_REDIRECT_VIEW

to the view that you want to redirect when the download completes.


Dropzone controls the upload process, so you should use Dropzone to redirect (make sure jQuery has been loaded).
Create an event listener, it will redirect the page when all the files in the queue have finished downloading:



<form action="{{ url_for('upload') }}" class="dropzone" id="my-dropzone" method="POST" enctype="multipart/form-data">
</form>

<script src="{{ url_for('static', filename='js/dropzone.js') }}"></script>
<script src="{{ url_for('static', filename='js/jquery.js') }}"></script>

<script>
Dropzone.autoDiscover = false;

$(function() {
  var myDropzone = new Dropzone("#my-dropzone");
  myDropzone.on("queuecomplete", function(file) {
    // Called when all files in the queue finish uploading.
    window.location = "{{ url_for('upload') }}";
  });
})
</script>

      

Handling redirection in view function:

import os
from flask import Flask, render_template, request

app = Flask(__name__)
app.config['UPLOADED_PATH'] = os.getcwd() + '/upload'

@app.route('/')
def index():
    # render upload page
    return render_template('index.html')


@app.route('/upload', methods=['GET', 'POST'])
def upload():
    if request.method == 'POST':
        for f in request.files.getlist('file'):
            f.save(os.path.join(app.config['UPLOADED_PATH'], f.filename))
    return redirect(url_for('where to redirect'))

      

+1


source


In this line:

if request.method == 'POST' and 'file' in request.files:

      



If the file exists in request.files, then "if file:" always returns True. Anywhere this code always works:

filename = secure_filename(file.filename)
file.save(os.path.join('./tmp/uploads', filename))
print '%s file saved' % filename

return redirect(url_for("blah.list_uploads"))

      

0


source


can help me in my situation?

this is a link to my question - why is my next page not loading after being redirected to its url?

0


source







All Articles