I’m pretty new to web development, so I’m just trying to see if I have the big picture right for what I am trying to do. Forgive me if any terminology is wrong.
My Django app needs to do the following:
- User uploads a file through his browser
- File is processed by the server (can take up to an hour)
- User sees the results in his browser
I’m having trouble on how to accomplish step 2…here is what I am thinking:
1.User uploads a file (pretty straightforward)
2.File is processed – a view function would go something like this:
def process(request):
a. (get file from the request)
b. (return a page which says "the server is running your job, results will be available in {ETA}")
c. (start processing the data)
3.User sees the results in his browser – Browser queries the server at regular intervals to see if the job is done. When the job ready, the browser gets the results.
My question is, in step 2 parts b and c, how can I return a response to the browser without waiting to the process to finish? Or, how can I ensure the process keeps running after I return the results to the browser? The process should ideally have access to the Django environment variables, as it will work with a database through Django’s interface.
You need to off load the processing. You could use django-celery.