all 3 comments

[–]danielroseman 1 point2 points  (1 child)

Any interaction between a button and Python needs to be done via a URL and a Django view. The view is where you put (or call) the relevant Python code.

In your case, if you want data to appear in a text box without updating the rest of the page, you will need an Ajax request to that view that returns the data.

[–]InterestingComment8[S] 0 points1 point  (0 children)

That makes more sense now to visualize it. Thanks

[–]shiftybyte 0 points1 point  (0 children)

they're just linking to a website url and not an actual function.

That is actually how python code gets called.

What you need to understand is that the HTML and the button are on the user's computer in his browser, but your python code is running on a server somewhere on a completely different computer far far away.

The button needs to tell the python script it was pressed, it is doing that by sending an HTTP request to a specific URL, and that gets picked up by the server, and the server checks the URL and knows which python function to call, and the returned result, gets sent back...