How do I map incoming “path” requests when using HTTPServer?

后端 未结 1 1130
野性不改
野性不改 2020-12-29 07:44

I\'m fairly new to coding in python. I created a local web server that says \"Hello World\" and displays the current time.

Is there a way to create a path, without

相关标签:
1条回答
  • 2020-12-29 08:18

    Very simple URL handler:

    def do_GET(self):
        if self.path == '/time':
            do_time(self)
        elif self.path == '/date':
            do_date(self)
    
    def do_time(self):
        self.send_response(200)
        self.send_header('Content-type','text/html')
        self.end_headers()
        # Send the html message
        self.wfile.write("<b> Hello World !</b>"
                         + "<br><br>Current time: " + str(datetime.datetime.now()))
    
    0 讨论(0)
提交回复
热议问题