That’s because the Python program is still running! A web server wouldn’t be very useful if it didn’t run all the time and wait around for people to visit its web pages. Note that unlike the print('Hello World') script, this one won’t have a trailing PS C:\Users\YOUR_USERNAME> after the program’s output. Run the script (“Run Python File in Terminal”, if using the VSCode play button in the upper right corner). TCPServer (( "", my_port ), my_handler ) as httpd : print ( "Http Server Serving at port", my_port ) httpd. getPath ())) my_handler = MyHttpRequestHandler with socketserver. read () return bytes ( content, 'utf-8' ) def do_GET ( self ): self. split ( '?' )) return content_path def getContent ( self, content_path ): with open ( content_path, mode = 'r', encoding = 'utf-8' ) as f : content = f. join ( my_html_folder_path, my_home_page_file_path ) else : content_path = path. end_headers () def getPath ( self ): if self. send_header ( 'Content-Type', 'text/html' ) self. SimpleHTTPRequestHandler ): def _set_headers ( self ): self. Import rver import socketserver from os import path my_host_name = 'localhost' my_port = 8888 my_html_folder_path = 'c: \\ example \\ ' my_home_page_file_path = 'my_web_page.html' class MyHttpRequestHandler ( http. I chose a folder called “some_other_folder” to demonstrate that the Python script and the HTML files don’t have to live in the same place on your computer. Once you know how to create and run Python files, create one at c:\some_other_folder\webserver.py. You need to be comfortable running a script called c:\example\hello.py whose source code is print('Hello World') on your computer and validating that you see your computer say “ Hello World” to you in the script execution environment’s “system output.”.You need to get all the way through the “Using our IDE to program” part of my article “ Setting up Windows Store Python with Pandas in VSCode” (or have installed Python your own way).Luckily, with Python, you can run a web server on your own computer, and you don’t even need administrator rights to the computer. To get the submit button in my_web_page.html to work, you have to deliver it to your web browser at an actual URL starting with Which means you have to put it on a web server. It’s literally just getting the submit button to work in my_web_page.html’s. It’s not the JavaScript in the confirmation page that doesn’t work with file:///C:/-style URLs. You might notice that if you visit file:///C:/example/the_confirmation_page.html?yesno_answer=maybe and play with the value of yesno_answer in the URL, everything works as expected. This is a second web page where I’d like the first web page to send my “yes/no/maybe” choice whenever I click the submit button. I'm a little web page I'm a little web page short and stout Yes No Maybe Īnd here’s the content of my file c:\example\the_confirmation_page.html.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |