If you want to experiment some python code as CGI script to serve by a HTTP server, you can get started by these steps:
- Create a
cgi-bin
directory. - Ready!
No, really, it's that simple! Try these CGI scripts out.
Example 1: cgi-bin/hello.py
#!/usr/bin/env python3
localvars_table = '<table>'
for x in dir():
localvars_table += '<tr><td>%s</td></tr>' % x
localvars_table += '</table>'
print("Content-type: text/html")
print("")
print("""<html><body>
<p>Hello World! Your custom CGI script is working. Here are your current Python local variables.</p>
%s
<p>NOTE: If you want to write useful CGI script, try the Python 'cgi' module. See cgitest.py script.</p>
</body></html>""" % (localvars_table))
To test and run this, you simply invoke these couple commands:
bash> chmod a+x cgi-bin/hello.py
bash> python3 -m http.server --cgi
You may now test it on your browser with http://localhost:8000/cgi-bin/hello.py. Hit CTRL+C
to stop the server.
If you want to do more with fancy CGI scripts, try the Python's cgi
module. Here is another example.
Example 2: cgi-bin/cgitest.py
#!/usr/bin/env python3
import cgi
cgi.test()
Again chmod
your cgitest.py
script and visit http://localhost:8000/cgi-bin/cgitest.py. You will see all the
HTTP related data as expected when working with a CGI script. See https://docs.python.org/3/library/cgi.html
for more details.
Wow! this is Amazing! Do you know your hidden name meaning ? Click here to find your hidden name meaning
ReplyDeleteThank you for this valuable information. We are in an ‘ always on ‘ world. Connecting, sharing, collaborating. We, at ISD Global, help brands digitell the digital while distinguishing the distinguished and distilling the brand essence. best digital marketing agencies in dubai.
ReplyDeleteThank you for the information. power bi certification
ReplyDeleteNice Post. Thank You For Sharing This Information.
ReplyDeleteSRI ANNAPOORNESHAWARI ASTROLOGY CENTER.Best Astrologer In dhule
Nicely well-written article. It was an awesome article to read. Complete rich content and fully informative.
ReplyDeleteFor sofa repair work contact thesofastore gives
Best Sofa Repair Services in Yemalur,Bangalore
Nice post.Keep sharing. Thanks for sharing.
ReplyDeleteDURGAANUGARHA ASTROLOGY.black magic Astrologer In kr-puram
Very nice & good looking posts,Thank you for sharing.
ReplyDeleteFor sofa renovation visit thesofastore,the provieds best
Sofa Refurbishing in HAL,Bangalore
This comment has been removed by the author.
ReplyDeleteAwesome blog post,Thank you.
ReplyDeletelook here
Best Astrologer in Srinagar
Nice blog with good content,thanks for sharing.
ReplyDeleteFor web design & development service contact Multisoft digital technologies, They have
Web Development in Koramangala
Hii your blog is looking good.Thanks for sharing this information and keep posting.
ReplyDeleteFor better sofa renovation contact thesofastore gives best
Best Sofa Repair Services in Austin Town,Bangalore
Good Article you know your article it's useful me. it's really good and helping your article and yes thanks for sharing information
ReplyDeleteFor sofa repair work contact thesofastore gives
Best Sofa Repair Services in Near Me
Awesome post, thanks for sharing
ReplyDeletePotato Chips Manufacturers in Kerala, Contact us potato chips manufacturers in Kerala
Its a Really good post,thansk for sharing
ReplyDeleteThe best astrological services contact. Best Astrologer In Lakshmi Devi Nagar
wow..amazing post blog that understand the value of providing a quality resource for free.
ReplyDeletevisit here
Bridal Jewellery for Rent in Basavanagudi
Very nice article came to know more about the topic.
ReplyDeleteBest Orthodontist in Bangalore, Contact us best orthodontist in bangalore
thanks for sharing nice blog keep posting like this if you like more visit it https://mulemasters.in/
ReplyDeleteNice article..
ReplyDeleteVisit website for best astrological services contact. Black Magic Astrologer in Hougang
Very good article,Thank you
ReplyDeleteFor Astrological service contact Shri Durga astro center,They gives
Vashikaran Astrologer in Kolar
Amazing blog post,Thank you.
ReplyDeletevisit here
Sofa Refurbishing in Doddanekundi
thanks for sharing nice blog keep posting like this https://mulemasters.in/
ReplyDeleteThank you for sharing very useful & informative article.
ReplyDeleteFor web design & development service contact Multisoft digital technologies, We have Digital Marketing in Channapatna
Such a great post, thanks for posting this kind of useful information
ReplyDeleteVisit our website for best astrological services contact. Vashikaran Astrologer in Tumkur
Nice post. Keep sharing. Thanks for sharing.
ReplyDeleteDurgaanugarha astrology center. Best Astrologer In malleswaram