Add a processing page between submit page and result page

11 views
Skip to first unread message

Ruifeng Hu

unread,
Nov 6, 2017, 2:46:41 PM11/6/17
to Django users
Hi All,

I am writing a project, on the submit page, a user submits some parameters, then the server side will take a calculation that may take a while, I want to add a waiting page to tall users that it is running on the server. When the result is ready, it will automatically jump to the result page.
I do not know what I should do to get these!

Is there anyone can help me!

Thank You!

Best,
Ruifeng Hu   

C. Kirby

unread,
Nov 7, 2017, 9:27:32 AM11/7/17
to Django users
You have two choices. One would be to use the relatively new Channels feature, which allows you to keep a communication stream open so that you would have the processing page show until the sever notified the client that it was done and sent the data. I've not worked with Channels much, so if you have questions about that you can follow up to this list.

The other option is to have a model that stores the result of the calculation. Example

class CalcResult(models.Model):
    result
= models.IntegerField(blank=True, null=True)

When the user submits the parameters you would create a new instance of this class:

current_calc = CalcResult.objects.create()

Now that you have that object you can pass the pk back to your processing view. Inside the processing view you can use javascript to poll the server with a view that checks if the pk has a result yet. when it gets a result you load the page that shows the result.

Be aware that you cannot do this in the standard request/response cycle.  When you send a response the interaction is done. In order to have your long running calculation work while the client is interacting with the system via a processing page you will need to use something like Celery or django-rq to offload the long running calculation.

Hope this helps,
Kirby

Adam Simon

unread,
Nov 7, 2017, 9:48:14 AM11/7/17
to django...@googlegroups.com
It seems to me that the easiest way to do this is via an Ajax call in JavaScript.  In my experience channels is very hard to set up.
--
--

Adam F. Simon, PhD
Calabasas, CA.

cell:      818-425-3719
home:   818-880-8405

Feel free to link w/ me: LinkedIn


Reply all
Reply to author
Forward
0 new messages