0

I'm having issues trying to get my browser to execute Python files and display them to the user. I'm brand new to Python so I'm sure it's just a stupid mistake or something I'm not understanding correctly.

I've tried to find tutorials online but there are so many different ones I'm not sure which is the correct way or what I'm doing wrong.

I am currently running Fedora 22 and have Python 3 installed. I have a directory on my desktop that looks like the following with the test.py being in the cgi-bin folder.

  • PythonFiles
    • cgi-bin
      • test.py

I then run python3 -m http.server from the PythonFiles directory so that it starts the server in that location.

However, when I navigate to localhost:8000 in my browser it just prints out the content/code of the python file. I have given the file permissions of 755 but that still doesn't work.

This is what my Python file looks like:

#!/usr/bin/env python3

print("Content-Type: text/plain;charset=utf-8")
print()

print(
"""
<html>
  <body>
    <h2>Python mde this</h2>
  </body>
</html>
"""
)

I know there's something I'm missing but I can't seem to figure out what I'm doing wrong. Thanks for any help!

Quiver
  • 1,351
  • 6
  • 33
  • 56
  • https://docs.python.org/2/library/simplehttpserver.html - here's the documentation saying *The SimpleHTTPServer module can also be invoked directly using the -m switch of the interpreter with a port number argument. Similar to the previous example, this serves the files relative to the current directory.* (i.e. your example is doing what it is supposed to do). – TessellatingHeckler Nov 19 '15 at 00:30
  • @Gil Thanks for referencing me to that question. That was exactly what I needed to solve my problem. Thanks again! – Quiver Nov 19 '15 at 00:35

0 Answers0