Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

242
Views
Django views with SSE and external scripts

If there is a better way to accomplish this, please let me know. I need to synchronously process data outside of a view, then only after data is processed in an external function redirect or open a new view.

  • File is uploaded from an HTML page, which routes the file to views.
  • Threading in views begins processing data in script outside of views.
  • Views returns a view to display the data as it's being processed using SSE.
  • External script sends data using send_event('test', 'message',{'text': stuff}

Here's where I'm stuck: I've tried using the Javascript event listener to watch for certain text that then does a window.open('newview'), as I have a view that downloads the CSV the script creates. I'm having a problem going from one view (with an active SSE connection) to another while waiting on the thread that is processing data to finish. I've tried a second thread in views.py that returns another response when thread x is finished.

I have to return render from the first view so that the live data shows to the client.

Html for upload:

<form action="/viewFunction/" method="POST" enctype="multipart/form-data" form target="_blank">
    {% csrf_token %}    
    <input type="file" id="fileform" name="filename">
    <input type="submit" id="fileform">

views.py:

def viewFunction(request):

    csv = pd.read_csv(request.FILES['filename'])
    file is uploaded from an html form
    x = threading.Thread(target=external.script, args=[csv])
    x.setDaemon(False)
    x.start()
        
    return render(request, 'html_that_displays_SSE_output.html')

external script.py:

iterate over CSV, making API calls
build CSV based on server responses
send_event('test', 'message', {'text': data}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!