[Answer]-Pass Data From Python To Html <p> Tag

1đź‘Ť

âś…

Part of your page that contains the paragraph tags is a piece of JavaScript that contains a timer.
Every once in a while it does an Ajax request to get the data with regard to “what’s going on now in the system”.

If you use the Ajax facilites of JQuery, which is probably the easiest, you can pass a JavaScript callback function that will be called if the request is answered. This callback function receives the data served by Django as response to the asynchroneous request. In the body of this callback you put the code to fill your paragraph.

Django doesn’t have to “know” about Ajax, it just serves the required info from a different URL than your original page containing the paragraph tags. That URL is part the your Ajax request from the client.

So it’s the client that takes the initiative. Ain’t no such thing as server push (fortunately).

Leave a comment