我使用的是Xampp7.2.6-0在ubuntu16.04和 Chrome 64.0.3282.186 (正式构建)(64位)。我正在尝试通过浏览器运行python脚本。我已经在/opt/lampp/etc中编辑了httpd.conf文件,并附加了以下行。
#edit by Wade King
AddHandler cgi-script .py
ScriptInterpreterSource Registry-Strict我的python脚本名为docxReader.py,在docxReader.py中
它看起来像这样,编译时没有错误:
#!/usr/bin/env python3
import cgitb
cgitb.enable()
print("Content-Type: text/html")
print("")
print("If you can read this inside a Web-Browser window, you can successfully run Python through XAMPP!'")在浏览器中键入http://localhost/PyFiles/XampPython/docxReader.py时,结果是docxReader.py文件的文本,如下所示:
#!/usr/bin/env python3
import cgitb
cgitb.enable()
print("Content-Type: text/html")
print("")
print("If you can read this inside a Web-Browser window, you can successfully run Python through XAMPP!'")我希望页面显示我的python文件的输出,而不是文件本身的文本。这里发生了什么,如何配置Xampp来显示python文件的输出?
发布于 2018-06-27 17:41:08
别管我想出来了,我把
AddHandler cgi-script .py
ScriptInterpreterSource Registry-Strict添加到httpd.conf末尾的行
然后我在httpd.conf中找到了这一行:
AddHandler cgi-script .cgi .pl并将.py追加到行中。
然后我运行chmod +x docxReader.py使其可执行,并在浏览器中打开该文件,它似乎正常工作。
https://stackoverflow.com/questions/51051621
复制相似问题