title: Django: create a "changing button" or waiting page
body: <p>I have an external python program, named <em>c.py</em>, which "counts" up to 20 seconds.
  I call it from my Django app <em>views.py</em> and in the html page I have a button to start it. It's ok (= in Eclipse I can see that c.py prints 0,1,2,3,...20 when I press the button on the webpage) but I would like that the button changes from "GO" to "WAIT" during <em>c.py</em> process (or I would like to perform a waiting page during the counting or also a pop-up). </p>
  
  <p><strong>c.py</strong></p>
  
  <pre><code>import time
  
  def prova(z):
      z = 0
      while z &lt; 20:
          time.sleep(1)
          z = z + 1
          print(z)
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>    from django.shortcuts import render_to_response
      #etc.
  
      import c
  
  
  def home_user(request):
      return render_to_response('homepage/home.html',{'user.username':request}, context_instance = RequestContext(request))
  
  def conta(request):
      c.prova(0)
      return redirect(home_user)
  </code></pre>
  
  <p>where in homepage.html I have the "GO" button that I would like to change in "WAIT" if the function <em>conta</em> is running.</p>
  
  <p><strong>urls.py</strong></p>
  
  <pre><code>        urlpatterns =patterns('',
      url(r'^homepage/home/$', views.home_user, name='home'),
      #etc.
      url(r'^conta', views.conta, name='conta'),
  
  
  )
  </code></pre>
  
  <p><strong>home.html</strong></p>
  
  <pre><code>{% if c.alive %}
  &lt;a href="" class="btn btn-danger" role="button"&gt;WAIT&lt;/a&gt;
  {% else %}
  &lt;a href="/conta/" class="btn btn-primary" role="button"&gt;GO&lt;/a&gt;
  {% endif %}
  </code></pre>
  
  <p>I don't put the whole code.. I hope this is sufficient to understand my trouble.
  I also see at <a href="https://stackoverflow.com/questions/8512143/how-to-create-a-waiting-page-in-django">How to create a waiting page in Django</a> but I would start with something simpler.</p>
  
  <p>Up to now when I start <em>c.py</em> I see that my web page is loading something (=it is "counting") but my button does not change and, <strong>after</strong> c.py execution, I return to <em>127.0.0.1:8000/homepage/home/</em> page.
  Is the problem in html or in my function definition or both?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I try to simplify the question:
  I found this script... </p>
  
  <pre><code>    &lt;button onclick="myFunction()"&gt;Try it&lt;/button&gt;
  
  &lt;p id="demo"&gt;&lt;/p&gt;
  
  &lt;script&gt;
  function myFunction() {
      var text = "";
      var i = 0;
      while (i &lt; 10) {
          text += "&lt;br&gt;The number is " + i;
          i++;
      }
      document.getElementById("demo").innerHTML = text;
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>I would like to "import" my <em>conta()</em> function in while instead of the cicle with i++</p>
  
  <p>i.e. I would like to have a similar thing:
  while <em>conta()</em> is running, appear something like <p>Waiting..</p> and when it stop i return to my home page.. I don't know how "put" <em>conta()</em> in the script.. is this possible? Am I a dreamer? :)</p>