Django: create a “changing button” or waiting page

前端 未结 2 903
野性不改
野性不改 2020-12-10 23:31

I have an external python program, named c.py, which \"counts\" up to 20 seconds. I call it from my Django app views.py and in the html page I have a butto

2条回答
  •  误落风尘
    2020-12-11 00:16

    I post my working solution. Thanks to @Brandon for the useful answer.

    in conta.js some changes:

    $(document).ready(function() {
    
        // avoid hard-coding urls...
        var yourApp = {
            contaUrl: "/conta/"
        };
    
    
        $('#btnGo').click(function(e) {
            e.preventDefault();  
            // set css classes and text of button
            $(this)
                .removeClass('btn-primary')
                .addClass('btn-danger disabled') // with *disabled* I'm sure that the button is not clickable
                .text('WAIT');
    
    
    
            $.get(yourApp.contaUrl, function(json) {     
                 alert("I have finished counting");                    
                 parent.window.location.reload(true);               
    
    
            });
        });
    });
    

    in views.py

    def conta(request):
        c.prova(0)
        redirect = reverse('home')                  
        return JsonResponse({'redirect': redirect})
    

提交回复
热议问题