使Python脚本适用于MAMP

Rav*_*eja 6 python web-applications mod-python

我正在使用mamp服务器来测试我的所有网页.我是python的新手.我能够在python解释器中运行一个脚本,通常会打印一个hello world.

print "Hello World!"   
Run Code Online (Sandbox Code Playgroud)

所以我在名为test.py的文件中使用了相同的行.那我该如何在网上运行呢.

作为python的新手,我尝试了一些正常的东西,将test.py放在/ htdocs/cgi-bin /中并尝试打开它.但它说禁止页面.

有人请帮我做这个工作.谢谢

Gre*_*att 5

要使用CGI执行此操作,我建议您阅读Python CGI文档.至少,您需要输出内容类型和html标记:

print "Content-Type: text/html"
print
print "<html>"
print "<head>"
print "<title>Example of Python CGI script</title>"
print "</head>"
print "<body>"
print "Hello World!"
print "</body>"
print "</html>"
Run Code Online (Sandbox Code Playgroud)

此外,请确保Web服务器软件具有执行脚本的权限.您应该能够使用chown来设置所有权,使用chmod来设置权限.