Jul-20-2017, 12:22 PM
Hey, Python community ! I used to code in C and some other languages like PHP(5 years back) then I changed career choice. Back then I just coded for fun but now I am looking for freelancing and that brings me back to development. I am learning from the edx course and so far this is how we are taught for the first web server
Quote:#BeginningBut I have realized nobody uses this approach(correct me if im wrong) and rather they rely on djangi,flask or the likes. For a freelancer which one should I go for? And from a learner's perspective, which one would be better for a beginner? Thank you
#python has its own builtin server support http.server
from http.server import BaseHTTPRequestHandler, HTTPServer
class HTTPServer_RequestHandler(BaseHTTPRequestHandler):
#GET
def do_GET(self):
#Send response code for get requests
self.send_response(200)
#send headers
self.send_header("Content-type","text/html")
self.end_headers()
#write message
self.wfile.write(bytes("<h1>howdy</h1>","utf8"))
return
port=8080
server_address=("0.0.0.0",port)
httpd=HTTPServer(server_address,HTTPServer_RequestHandler)
httpd.serve_forever()
#END