{"id":7056,"date":"2014-04-03T05:02:22","date_gmt":"2014-04-02T18:02:22","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=7056"},"modified":"2014-04-03T05:02:22","modified_gmt":"2014-04-02T18:02:22","slug":"python-webserver-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/python-webserver-primer-tutorial\/","title":{"rendered":"Python Webserver Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Python\/WebServer\/\"><img decoding=\"async\" id='pimqgmovh' onmouseover=\"var xqw=this.src;  if (xqw.indexOf('6') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Python\/WebServer\/Python_WebServer-1of.jpg'; } else if (xqw.indexOf('1') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Python\/WebServer\/Python_WebServer-2of.jpg'; }  else if (xqw.indexOf('2') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Python\/WebServer\/Python_WebServer-3of.jpg'; } else if (xqw.indexOf('3') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Python\/WebServer\/Python_WebServer-4of.jpg'; } else if (xqw.indexOf('4') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Python\/WebServer\/Python_WebServer-5of.jpg'; } else if (xqw.indexOf('5') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Python\/WebServer\/Python_WebServer-6of.jpg'; }  \"  style=\"float:left;border: 15px solid pink;\" alt=\"Python Webserver Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Python\/WebServer\/Python_WebServer-6of.jpg\" title=\"Python Webserver Primer Tutorial (try twirling round bottom of image for a synopsis ... 'do the twirl now')\"  \/><\/a><p class=\"wp-caption-text\">Python Webserver Primer Tutorial (try twirling round bottom of image for a synopsis ... 'do the twirl now')<\/p><\/div>\n<p>Today&#8217;s tutorial shows yet another approach regarding the creation of a local Web Server.   Today we create a very simple Python Web Server, and give thanks to <i>Python and XML<\/i> by Christopher A. Jones and Fred E. Drake, for the excellent &#8220;basis&#8221; code on pp 198-200.   This tutorial could use <a target=_blank title='Go Webserver Primer Tutorial' href='#gwpt'>Go Webserver Primer Tutorial<\/a> as shown below, for compare and contrast purposes, and you may want to refer to our growing list of Web Server ideas at <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=4112' title='Cassini++ WebServer Primer Tutorial'>Cassini++ WebServer Primer Tutorial<\/a> and perhaps <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=3491' title='Web Server Primer Tutorial'>Web Server Primer Tutorial<\/a> and maybe <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=4066' title=\"Apache WebServer on Mac and The Three P\u2019s Primer Tutorial\">Apache WebServer on Mac and The Three P\u2019s Primer Tutorial<\/a>.<\/p>\n<p>As one of the Three P&#8217;s you&#8217;d expect Python to be capable of this, and, indeed, it can be a complete replacement for PHP as your server-side language.   Believe it is growing in popularity, and can see its appeal for the clear-thinkers amongst us.   Its data structures are appealing to many programmers, and with more and more Python code written, the more powerful it will become in the Open Source world.<\/p>\n<p>So this Python&#8217;s Web Server &#8220;ingredients&#8221; (ie. methods) for class ourRequestHandler are:<\/p>\n<ul>\n<li>do_GET helps with GET requests<\/li>\n<li>do_POST helps with POST requests<\/li>\n<li>ourPrintBrowserHeaders prints HTTP headers<\/li>\n<li>ourPrintCustomHTTPResponse takes response and sends code and custom headers back to browser<\/li>\n<\/ul>\n<p>Link to downloadable Python programming source code for a rudimentary webserver could be called <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Python\/WebServer\/PythonHTTPServer.py_GETME\" title=\"PythonHTTPServer.py\">PythonHTTPServer.py<\/a> (which oversees the &#8220;POST&#8221; test HTML <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Python\/WebServer\/ourTestFormPage.html_GETME\" title=\"ourTestFormPage.html\">ourTestFormPage.html<\/a>) as you wish.<\/p>\n<p>Are you looking for a commercial Python web framework?   You could try <a target=_blank title='Django' href='https:\/\/www.djangoproject.com\/'>Django<\/a>.<\/p>\n<p>Will leave you with a <a target=_blank title='Yes, it is true' href='http:\/\/www.youtube.com\/watch?v=G6D1YI-41ao'>chuckle<\/a>, m&#8217;lord.<\/p>\n<hr \/>\n<p id='gwpt'>Previous compare and contrast <a target=_blank title='Go Webserver Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=3969'>Go Webserver Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Go\/Webserver\/Go_Webserver_Primer.jpg\"><img decoding=\"async\"  style=\"border: 15px solid pink;\"  style=\"float:left; border: 15px solid pink;\" alt=\"Go Install Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Go\/Webserver\/Go_Webserver_Primer.jpg\" title=\"Go Webserver Primer Tutorial\" \/><\/a><p class=\"wp-caption-text\">Go Webserver Primer Tutorial<\/p><\/div>\n<p>Did you wake up wanting to write your own Web Server?   No?   Well, what are WE to do with YOU?   <em>&#8220;Lefty?   Mugsy?   Priscilla?   Let &#8217;em &#8216;av it?    Yes, the web server, you &#8216;eard what oi said!   Sorry, you&#8217;re having lunch?&#8221;<\/em><\/p>\n<p>&#8230; four hours later &#8230;<\/p>\n<p><em>&#8220;Mugsy, what&#8217;s that triangular piece of paper &#8230; never mind &#8230; have you got that web server?&#8221;<\/em><\/p>\n<p>(Metallic tinkering sound)<\/p>\n<p><em>&#8220;You do know what a web server is, don&#8217;t you?  What&#8217;s that you&#8217;ve got there on that silver thing behind your back?&#8221;<\/em><\/p>\n<p><strike>(Metallic tinkering sound)<\/strike> &#8230; replaced by (Metallic sounds that are tinkering)<\/p>\n<p><em>&#8220;Lefty, do you know what is behind Mugsy&#8217;s back &#8230; and why have you got one of those triangular pieces <strike>of pap<\/strike> &#8230; oh, never mind.   Is that a link you want me to click?&#8221;<\/em><\/p>\n<p>.<\/p>\n<p>.<\/p>\n<p>.<\/p>\n<p>.<\/p>\n<p>.<\/p>\n<p>.<\/p>\n<p>.<\/p>\n<p>.<\/p>\n<p><a href='#showme' onclick=\" var xxx=document.getElementById('showme');  xxx.style.display='block'; var xxxd=document.getElementById('dshowme');  xxxd.style.display='block';\">V<\/a><\/p>\n<p><a href='#showme' style='color:pink;' onclick=\" var xxx=document.getElementById('showme');  xxx.style.display='block'; var xxxd=document.getElementById('dshowme');  xxxd.style.display='block';\">Welcome to Mugsy&#8217;s and Lefty&#8217;s personalized link<\/a><\/p>\n<div style=\"width: 380px; height: 260px; overflow: hidden\">\n<img id='showme' src='http:\/\/www.findaspider.org.au\/info\/images\/Recognizing nests.jpg' style='display:none; margin-left:-350px;' title='Thanks to http:\/\/www.findaspider.org.au\/ for the image' onclick=' window.open(\"http:\/\/www.findaspider.org.au\/\");'><\/img>\n<\/div>\n<p id='dshowme' style='display:none;'>Da da da da!   &#8230; or should that be &#8230; Do do, do do, do do, do do!<\/p>\n<p>Our tutorial today builds on previous <a target=_blank href=\"#gipt\">Go Install Primer Tutorial<\/a> as shown below.<\/p>\n<p>Link to downloadable Go programming source code for a rudimentary webserver (about animals) could be called <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Go\/Webserver\/webserver.go_GETME\">webserver.go<\/a> as you wish.<\/p>\n<p>Link to Go &#8220;spiritual home&#8221; at <a target=_blank title='Go at Google' href='http:\/\/code.google.com\/p\/go\/'>Google<\/a>.<\/p>\n<p>Link to really good Go tutorials at <a target=_blank title='Go tutorials at Google' href='http:\/\/tour.golang.org\/'>Google<\/a>.<\/p>\n<p>Link to Go 1.1 Google Open Source Blog is <a target=_blank title='Go Open Source Blog' href='http:\/\/google-opensource.blogspot.hu\/2013\/05\/go-11-is-released.html'>here<\/a>.<\/p>\n<p>Link to really good Go web information at  <a target=_blank title='Go web information at Google' href='http:\/\/golang.org\/doc\/articles\/wiki\/#tmp_3'>Google<\/a>.<\/p>\n<hr \/>\n<p id='gipt'>Previous <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Go\/\">Go Install Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Go\/\"><img decoding=\"async\" id='imgigmail' onmouseover=\"var xqw=this.src;  if (xqw.indexOf('5') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Go\/Go_Google_Primer-0of.jpg'; } else if (xqw.indexOf('4') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Go\/Go_Google_Primer-5of.jpg'; } else if (xqw.indexOf('3') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Go\/Go_Google_Primer-4of.jpg'; }    else if (xqw.indexOf('2') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Go\/Go_Google_Primer-3of.jpg'; } else if (xqw.indexOf('1') != -1) { this.src = 'http:\/\/www.rjmprogramming.com.au\/Go\/Go_Google_Primer-2of.jpg'; }  else { this.src = 'http:\/\/www.rjmprogramming.com.au\/Go\/Go_Google_Primer-1of.jpg'; } \"  style=\"border: 15px solid pink;\"  style=\"float:left; border: 15px solid pink;\" alt=\"Go Install Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Go\/Go_Google_Primer-3of.jpg\" title=\"Go Install Primer Tutorial (try twirling round bottom of image for a synopsis ... 'do the twirl now')\" \/><\/a><p class=\"wp-caption-text\">Go Install Primer Tutorial (try twirling round bottom of image for a synopsis ... 'do the twirl now')<\/p><\/div>\n<p>Go (by Google) gave me that feeling like you are just seeing the tip of the iceberg, again.   A friend kindly put me onto this as a programming language which is an alternative to OOP but not just a function call type of language.<\/p>\n<p>Here we just install it (on a Mac 64bit laptop with Mac OS X 10.7.5) and do the old &#8220;<a target=_blank title=\"Don't say I don't give you anything\" href='http:\/\/www.rjmprogramming.com.au\/Go\/hw.jpg'>Hello World<\/a>&#8220;, but we will explore more in tutorials to come, and in any case here we do 4 x &#8220;hello world&#8221; with 3 different programs.   Meanwhile, have a read from <a target=_blank title='Go (2009) information from Wikipedia' href='http:\/\/en.wikipedia.org\/wiki\/Go_%28programming_language%29'>Wikipedia<\/a> about it, below:<\/p>\n<blockquote><p>Go, otherwise known as Golang, is an open source, compiled, garbage-collected, concurrent system programming language. It was first designed and developed at Google Inc.[7] beginning in September 2007 by Robert Griesemer, Rob Pike, and Ken Thompson.[3]<\/p>\n<p>The language was officially announced in November 2009 and is now used in some of Google&#8217;s production systems.[8] Go&#8217;s &#8220;gc&#8221; compiler targets the Linux, Mac OS X, FreeBSD, OpenBSD, Plan 9, and Microsoft Windows operating systems and the i386, amd64, and ARM processor architectures.[9]<\/p><\/blockquote>\n<p>You can download go (2009) programming source codes and rename to <a target=_blank title='Hello World in go (2009)' href='http:\/\/www.rjmprogramming.com.au\/Go\/hello.go_GETME'>hello.go<\/a>,  <a target=_blank title='Hello World in go (2009)' href='http:\/\/www.rjmprogramming.com.au\/Go\/helloworld.go_GETME'>helloworld.go<\/a>,  <a target=_blank title='Hello World x 2 in go (2009)' href='http:\/\/www.rjmprogramming.com.au\/Go\/slice.go_GETME'>slice.go<\/a>.<\/p>\n<p>Link to Go &#8220;spiritual home&#8221; at <a target=_blank title='Go at Google' href='http:\/\/code.google.com\/p\/go\/'>Google<\/a>.<\/p>\n<p>Link to really good Go tutorials at <a target=_blank title='Go tutorials at Google' href='http:\/\/tour.golang.org\/'>Google<\/a>.<\/p>\n<p>Link to Go 1.1 Google Open Source Blog is <a target=_blank title='Go Open Source Blog' href='http:\/\/google-opensource.blogspot.hu\/2013\/05\/go-11-is-released.html'>here<\/a>.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d3121' onclick='var dv=document.getElementById(\"d3121\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?cat=42\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d3121' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d3969' onclick='var dv=document.getElementById(\"d3969\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?cat=42\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d3969' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d7056' onclick='var dv=document.getElementById(\"d7056\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=Python\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d7056' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Today&#8217;s tutorial shows yet another approach regarding the creation of a local Web Server. Today we create a very simple Python Web Server, and give thanks to Python and XML by Christopher A. Jones and Fred E. Drake, for the &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/python-webserver-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,37],"tags":[345,558,714,877,997,1012,1319],"class_list":["post-7056","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-django","tag-hello-world","tag-local-web-server","tag-open-source","tag-programming","tag-python","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/7056"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=7056"}],"version-history":[{"count":0,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/7056\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=7056"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=7056"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=7056"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}