Running Python scripts with Xampp

后端 未结 4 1062
故里飘歌
故里飘歌 2020-11-29 05:50

I\'m using python 2.7.13
At first the browser was showing the raw code.

what I did:

Edited httpd.conf

AddHandler cgi-script .cgi .pl .as         


        
4条回答
  •  孤城傲影
    2020-11-29 06:16

    Im running ubuntu 16.04 so my answer might be a little different. I am using a google chrome browser with a python 3 file called test.py in /opt/lampp/htdocs/PythonProject:

    #test.py
    #!/usr/bin/env python3
    print('Content-type: text/html\r\n\r')
    print("

    hello world!

    ") print("I can view this in my browser yay!!")

    I edited my httpd.conf file in /opt/lampp/etc/httpd.conf and I did not add

    AddHandler cgi-script .py
    ScriptInterpreterSource Registry-Strict
    

    to the end of the file, instead I added .py to the end of the existing line

    AddHandler cgi-script .cgi .pl
    

    finally i made the file executable by chmod +x /opt/lampp/htdocs/PythonProject/test.py and then I just ran it through my browser:

    http://localhost/PythonProject/test.py
    

    OUTPUT:

    hello world!
    
    I can view this in my browser yay!!
    

提交回复
热议问题