'How to set up a loading screen for a form that takes time to process in Django?

I have the following view (with some code removed for simplicity):

def add_entry(request, num):
    form = ModelForm1()
    form2 = Form2()
    if request.method == 'POST':
        form = ModelForm1(request.POST)
        form2 = Form2(request.POST)
        if form.is_valid() and form2.is_valid():
            text = form2.cleaned_data['text']
            database_dict = process_data(text)
            # Some code here that dictates how data is saved from the dictionary....
            entry.save()
            return redirect('entries', num)
    return render(request, 'app/add_entry.html', {"form": form, "form2": form2})

Basically, this view contains a form which takes a text input. That text input is processed through a function with returns a dictionary of values. Those values are then stored in a database, and this database is rendered to the template "entries.html".

Depending on the amount of text in the form, it can take quite some time to process, and this time is spent in the input-screen of the form. I would like to add an interim "loading"-screen which the user is taken to while the form is processed, which then redirects to entires.html after the processing is done, but I can't seem to find out how. Adding a redirect without the "return" statement right after the data is processed doesn't seem to do anything, and adding the "return" messes everything up.

How do I do this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source