dir.by  
Поиск >>

Компьютер, программы
→
Python
 Python пример: "HTTP server" 
посмотрели 4872 раз
обновлено: 8 February 2021
Создадим файлы:
  Файл my.py
import http.server
import socketserver

PORT = 9000

class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler):
    def do_GET(self):
        self.path = 'index.html'
        return http.server.SimpleHTTPRequestHandler.do_GET(self)

Handler = MyHttpRequestHandler

with socketserver.TCPServer(("", PORT), Handler) as httpd:
    print("Http Server Serving at port", PORT)
    httpd.serve_forever()
  Файл my.sh
python my.py
$SHELL
exit 1
  Файл index.html
<body>
     <h3>Hello!</h3>
</body>
В командной строке запустим файл my.sh
Откроем браузер Google Chrome и введем
http://localhost:9000/

в результате увидим:
 
← Previous topic
Python example: "Download tasks from Redmine"
 
Next topic →
Sites to learn Python
 
Your feedback ... Comments ...
   
Your Name
Your comment (www links can only be added by a logged-in user)

Новость "Черная пятница" на технику Dreame в Беларуси с 17 по 30 ноября 2026 года – две недели скидок до 3400 рублей
 
• Download and install Python for Windows
New app
Option 1. Create a new application in a text editor and run it on the command line
• Create a new Python application in a text editor and run it on the command line
Option 2 (the best for me). Creating a New App in Visual Studio Code
• Creating a new application with Python in Visual Studio Code. Debugging the application. See how Python is executed step by step in debugging
Python syntax, functions, classes
• How do you check in Python if an object has an attribute?
Examples
• Python example: "Open the XML file and read the sections and save it to the txt file"
• Python example: "Download tasks from Redmine"
• Python example: "HTTP server"
Sites to learn Python
• Sites to learn Python

  Ваши вопросы присылайте по почте: info@dir.by