exiting a VPython/python script

13 views
Skip to first unread message

Louis King

unread,
Nov 19, 2025, 7:40:33 PMNov 19
to VPython-users
My apologize for the only tangentially related topic.
After ~2yrs my VPython simulation is getting close to being ready for prime time - a public facing web application. I found a tutorial for how to call a python script from a php/html web script. Works fine. 

I haven't been able to fined the python process to get back to my php/html menu. I do properly close the VPython graphics so that a <print> command works as expected, printing on the blank browser screen. But I have not figured out how to direct the browser to redirect/call a html script.

I did post this question where I found the html -> python link. I also noticed the other most current post was 2yrs+ old so am not hopeful. Thanks for any pointers in the right direction.

John

unread,
Nov 20, 2025, 10:03:35 AMNov 20
to VPython-users
I entered your question into google and the AI reply was

To redirect the user's browser back to your HTML menu page after the Python script finishes, you need to send an HTTP Location header or use an HTML meta-refresh tag within the Python script's output. 
Since you are already using print commands in your Python script to output to the browser, you can add the necessary headers or tags to control the browser's behavior. 
Method 1: Using the HTTP Location Header (Recommended)
This is the standard and most efficient way to perform a redirect. The key is that the Location: header must be printed before any other content, including the Content-Type header and the blank line. 
In your Python script, replace your existing print statements with the following code at the very beginning of the script's output:

The AI reply also provided a bunch of links on implementations. So you should try asking google search yourself and and see what the response is from AI. The google AI is called Gemini 3 and it is one of the top rated AI systems available now. 

Louis King

unread,
Nov 20, 2025, 7:22:49 PMNov 20
to vpytho...@googlegroups.com
Thanks. I am continuing to wander through search engine suggestions. What seems to be common is that suggestions overlooking that my python script is a VPython graphics application and sends lots of content to the user's browser before coming to the end. AND as your post highlights
" The key is that the Location: header must be printed before any other content, including the Content-Type header and the blank line.  "
--
You received this message because you are subscribed to the Google Groups "VPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vpython-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/vpython-users/15ecf423-f3cd-4212-9a65-7fe782ef8079n%40googlegroups.com.


--
Lou
Say what you will about Sisyphus. He always has work.

John

unread,
Nov 20, 2025, 8:32:03 PMNov 20
to VPython-users
You can also look into webvpython running in a browser like these vpython demo programs

https://glowscript.org/#/user/GlowScriptDemos/folder/Examples/

Maybe your vpython script can run as web vpython if it is a pure python application. 

You can try click on Share or export this program  for any of these demo programs to see the options to include it in an html page.
Reply all
Reply to author
Forward
0 new messages