Forums

File upload progress bar that uses xhr and jQuery working on local machine and not on Python Anywhere

I have a Django model form that has file fields. Since the files sent by the users are larger, I am submitting the form using xhr request and jQuery. The progress bar works fine on local machine. But it's stuck at 0% when I try the same in pythonanywhere. The file is still uploading but I am unable to track the progress. Once upload finishes I am receiving the success status and all. I am using this library https://github.com/jakobadam/bootstrap-uploadprogress

In my HTML I just call

$("#form").uploadprogress({redirect_url: "my_url"});

My views:::python

def signup_view(request):
    status = 200
    if request.method == 'POST':
        logout(request)
        form = SignUpForm(request.POST)
        file_form= FileProfileForm(request.POST, request.FILES)
        if form.is_valid() and file_form.is_valid():
            userObj = form.cleaned_data
            username = userObj['username']
            email = userObj['email']
            password = userObj['password1']
            if not (User.objects.filter(email=email).exists()):
                user = form.save()
                file_inst= file_form.save()
                data = {'status': 200, 'message': 'Account created successfully'}
                return JsonResponse(data, safe=False)
            else:
                raise forms.ValidationError('Looks like a username with that email or password already exists')
        else:
            status = 422
    else:
        form = SignUpForm
        file_form= FileProfileForm(initial={'status': 'Pending'})
        context = {'form': form, 'file_form': file_form}
    return render(request, 'registration/signup.html', context, status=status)

I am new here so please let me know if I am missing something :)

Thanks in advance

Check for errors in the network and console tabs of your browser developer tools. That will be the starting point that you can use to start debugging.

I figured it out and then it started behaving normally. I am totally confused lol. I was hitting my head against the wall and then I noticed that there's a lot of delay in getting the xhr.upload.progress I don't know why. But then it started working-ish. There is still a lot of delay in receiving the upload progress but I have no clue what's causing this. One thing could be bandwidth bottleneck on the server-side because of my free account. Would appreciate if someone can shed some light on the possible causes, Thank You

And Thank You soo much glenn!!! You pointed me in the right direction

Free accounts have only one web worker process. If it's busy, requests have to wait. That could be the problem in your case.