I am using Windows 7 and Python 3.4.3. I would like to run this simple helloworld.py file in my browser:
print('Content-Type: text/html')
print( '<html>')
print( '<head></head>')
print( '<body>')
print( '<h2>Hello World</h2>')
print( '</body></html>')
What I do is:
1) Go to command line C:\Python
(where python is installed)
2) run: python -m http.server
3) Got to Firefox and type http://localhost:8000/hello.py
However, instead of "Hello World", the browser just prints the content of the hello.py file.
How can I fix it?
From the
http.server
docs:Put your script into
cgi_directories
:Open in the browser:
where
hello.py
:I had to make it executable on POSIX:
chmod +x cgi-bin/hello.py
.I created a complete example for a friend. It is a complete demo you can run with 8 simple copy-paste ready lines of code. Enjoy.
I did this some time ago for Python2.7
So in Python 3 you just need to change imports
I do not know right now if the print-function in python 3 is
or
but i guess it was with ()
Edit: it is print()