In the directory with scripts I start the server in the following way:
python -m http.server 8000
the server starts normally but instead displays the script code. What should I do to see the output of the print function only?
In the directory with scripts I start the server in the following way:
python -m http.server 8000
the server starts normally but instead displays the script code. What should I do to see the output of the print function only?
Run python -m http.server --cgi
Create a cgi-bin
Create a file \cgi-bin\hello.py
#!/usr/bin/env python print("Content-type: text/html") print() print("<h1>Hello world!</h1>") Here is the article in addition https://pythonworld.ru/web/cgi-1.html
So it happened:
we have scripts (we create ourselves):
C: \ python \ srv.py
from http.server import HTTPServer, CGIHTTPRequestHandler server_address = ("", 8000) httpd = HTTPServer(server_address, CGIHTTPRequestHandler) httpd.serve_forever() C: \ python \ cgi-bin \ hello.py
#!/usr/bin/env python print("Content-type: text/html") print() print("<h1>Hello world!</h1>") run the srv.py script
go to the browser by reference: http: // localhost: 8000 / cgi-bin / hello.py
EVERYTHING
and note just follow the link to the cgi-bin directory without specifying the file you will fail. the server just curses it.
srv.py , you can python3 -m http.server 8000 --cgi . - jfspy -3 command or check which version just python -V runs python -V . Such elementary adaptations you must do yourself. - jfspython3 -m http.server ... You answered: "I did not find such an ekzeshnik in the installation directory, in Linux it may be" If you are able to run a python, then you should not have any problems to adapt and run: python3 -m http.server .. command for your system. - jfsSource: https://ru.stackoverflow.com/questions/608377/
All Articles