-2

I have a question regarding a Python running problem. I set up a local server with the Windows command prompt using the python -m http.server 8000 command, but when I run my script on http://localhost:8000/cgi-bin/hello.py, it just shows me the source code instead of actually running the script.

I use the code i found on this link.

#!/usr/bin/python

print('Content-Type: text/html')
print()
print('<html>')
print('<head><title>Hello from Python</title></head>')
print('<body>')
print('<h2>Hello from Python</h2>')
print('</body></html>')

I've seen several people having the same problem, but I couldn't really find a solution. I work with Python 3.5

5
  • 1
    did you start it with python -m CGIHTTPServer? like on the page you linked? Commented May 3, 2016 at 9:27
  • Follow all of the instructions on that page. Not just some of them. -1 Commented May 3, 2016 at 9:28
  • Possible duplicate of Printing HTML in Python CGI Commented May 3, 2016 at 9:28
  • When i tried using python -m CGIHTTPServer, it didn't work and i looked in the python docs and found they merged all their server commands it in the python -m http.server command. Doesn't it work the same way? Commented May 3, 2016 at 9:32
  • No. http.server serves the files in the directory and can be useful if you are having static html pages. For executing python apps (or PHP or any other dynamic language which generates html files) you need CGI or some other gateway interfaces. Now as @Daniel suggests you could use --cgi option. Commented May 3, 2016 at 9:40

1 Answer 1

1

You should follow the documentation. The command for Python 3 is:

python -m http.server --cgi 8000
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.