title: How to run a long process/function on button click django
body: <p>Im trying to do a django website in which:</p>
  <ol>
  <li>I take a user input from the template (done)</li>
  <li>Save the input in the view (done)</li>
  <li>On a button click, user starts a function that send a api request every x seconds and if the function find a different api response then show it in template as status.</li>
  </ol>
  <p>And i have no idea how to achieve the 3rd point. This is how the api request function looks like:</p>
  <pre><code>def function(zapytaniex,fraza,kategoria): 
      starttime = time.time()
      data1 = zapytaniex
      while True:
          data2 = apirequest(fraza = fraza, categoryid = kategoria)
          if data1 != data2:
              context[&quot;status&quot;] = &quot;got new offer&quot;
                                  
          elif data1 == data2:
              context[&quot;status&quot;] = &quot;still nothing&quot;
  
          time.sleep(120.0 - ((time.time() - starttime) % 120.0))
  
  </code></pre>
  <p>As you can see this function send the api request every 2 minutes and I want to run this function when user clicks a button and then update a status context in a template WITHOUT refreshing the whole page.
  I tried to run it with threading but the page keep loading when the thread in working.</p>
  <p>Thanks for any help and ideas!</p>