2011-10-31 4 views
0

클라이언트/사용자/고객이 제출 버튼을 누르면 매우 긴 작업이 실행됩니다. 장고를 사용하여 질의가 끝날 때까지 쿼리를 실행하라는 메시지를 어떻게 표시 할 수 있습니까?서버가 쿼리를 실행하는 동안 메시지 표시 Django

+0

왜 작업에 엔큐를 넣지 않으시겠습니까? (스레드, 셀러리, ....). (죄송합니다, 이것은 예상 답변이 아닙니다. 응답은 '제출 버튼'을 클릭 할 때로드 메시지 표시, 요청을받은 새 페이지가 이전 페이지를 오버라이드하고 '로드 메시지'가 제거 된 것일 수 있습니다. : http://thecrumb.com/2011/01/21/simple-loading-dialog-wjquery-ui/) – danihp

+0

제출시 프론트 엔드 자바 스크립트를 사용하여 메시지를 표시하십시오. 이것은 더 큰 문제의 시작처럼 들리지만 비동기 솔루션을 사용하는 것을 고려해야합니다. –

답변

0

이 내가 버튼을 누른를 결정하는 몇 가지 코드를 jQuery를 사용하여 포함하고 결국 무엇을 :

<form> 
<div id="loading" style="display:none;">Finding all words, may take a long time</div> 
<div id="form_input_things"> 
<input type="submit" name="_save" value="Save" /> 
<input type="submit" name="_get_words" value="Get Words" /> 
{{ form.as_p }} 
</div> 
</form> 

<script> 
    $("form").submit(function() { 
    { 
     if($("[submit_button_pressed=Save]").get(0) === undefined) 
     { 
     $('#loading').show(); 
     $('#form_input_things').hide(); 
     } 
    } 
    return true;  
    }); 

    $(":submit").live('click', function() { 
     $(this).attr("submit_button_pressed", $(this).val()); 
    }); 
</script> 
+0

이 코드는 초기 질문에 응답하지 않습니다. 그건 그렇고, 내 대답을 받아들이지 않는 것에 대해 감사합니다 ... –

+0

그것은 내 질문에 대답합니다. 메시지가 나타나고 쿼리/제출이 새 페이지를 반환하면 결과가 표시됩니다. 또한 사용하기가 더 쉽습니다. – Martlark

1

이렇게하려면 Ajax를 사용해야합니다.

JQuery를 사용하는 예를 보겠습니다. 템플릿에,이 양식이있는 경우 :

<form id="my_form" action="" method="post"> 
    <label for="age">Age:</label> 
    <input type="text" name="age" id="age"/> 
    <input type="submit" value="Submit"/> 
</form> 
<div id="loading" style="display:none;">Loading...</div> 

당신이 이미 가지고있는 JQuery와 lib에 포함 가정의 일부 자바 스크립트 만들어 보자 : 당신은 완전히 일에 대한 코드의 조각을 사용자 정의 할 수 있습니다

$(function(){ 
    $('#my_form').submit(function(event){ 
     event.preventDefault(); 

     alert('user submitted the form'); 
     $('#loading').show(); 

     $.post('my_url', 
       {age : $('#age').val()}, 
       function(data){ 
        $('#loading').hide(); 
        alert('server finished to process data.'); 
       }); 
    }); 

}); 

무엇 네가 원해. 그리고 당신은 아약스에서 더 디버깅을 원하는 경우, 당신은이 방법으로 다음과 같은 당신의 ajaxSetup를 선언하는 것이 좋습니다 :

function ajaxSetup(){ 

    $.ajaxSetup({ 
     error:function(x,e){ 
      if(x.status==0){ 
       alert('You are offline!!\n Please Check Your Network.'); 
      }else if(x.status==404){ 
       alert('Requested URL not found.'); 
      }else if(x.status==500){ 
       alert('Internal Server Error.\n' + x.responseText); 
      }else if(e=='parsererror'){ 
       alert('Error.\nParsing JSON Request failed.'); 
      }else if(e=='timeout'){ 
       alert('Request Time out.'); 
      }else { 
       alert('Unknow Error.\n'+x.responseText); 
      } 
     } 
    }); 
} 
+0

그다지 장고하지 않습니다. – Martlark

+0

@Martlark Django에서 아약스를 사용하고 싶다면이 프로젝트를 http://www.dajaxproject.com/ mightout 도움이 되십시오 :) –

+0

오후에 잠들지 않을 때 나는 dajaxproject로 시도 할 것입니다. – Martlark

관련 문제