-1

This below code is my html.py file in my cgi-bin directory.

print "Content-type:text/html"
print '<html>'
print '<head>'
print '<title>Hello Word - First CGI Program</title>'
print '</head>'
print '<body>'
print '<h2>Hello Word! This is my first CGI program</h2>'
print '</body>'
print '</html>'

I started my server using the below command:

python -m CGIHTTPServer 8000

And I'm opening my html.py file in my browser like below.

enter image description here

When I'm checking in network , it is showing 200 OK, but I'm not getting any response. Do I need to configure anything to run the scripts?

I'm new to python. Please help me resolve this issue.

Alex Waygood
  • 6,304
  • 3
  • 24
  • 46
  • have you got `#!/usr/bin/env python` or your path to python at the top of the file to make it executable. Also check that the file has 755 permissions – Riley Nov 25 '16 at 13:50
  • Do you have `AddHandler cgi-script .py` in your server setup? This shows you how to get a file working http://raspberrywebserver.com/cgiscripting/writing-cgi-scripts-in-python.html – Riley Nov 25 '16 at 13:55
  • This is another good tutorial to get started with python for websites https://pythonschool.net/category/server-side-scripting.html – Riley Nov 25 '16 at 13:58

1 Answers1

-1

I'm not sure what you want, but I'll try to help you.

  • When you want to run python code in your browser, you can do that. The most of the browsers can also use python code (for example: use brython). I think it's possible that anyone's browser can't run it, but I'm not sure in it. I think, brython can't do anything with print command (because a browser hasn't got an output field out of its window box).

  • When you want to include html from your python server, I would suggest, using http.server, which is simple to use, in my opinion.

  • When you want to open this file in your browser, and you want to run it in your browser, you can't do this (I think). Use python's http.server, then you can treat this request, and you can send this in html code, and when you use brython, the user can run it in their browser.

Please let me know if anything in my answer was unclear.

Alex Waygood
  • 6,304
  • 3
  • 24
  • 46
Nohab
  • 39
  • 6