首页 > 解决方案 > 如何解决在本地运行我的 python 代码?

问题描述

我已经安装了 python 3.7 版本。当我在命令中运行时,它的效果很好。但是当我尝试运行 http.server 8000 然后浏览 url 然后只显示我的 index.py 代码而不是像网页那样运行。

对此有任何想法。

我确实更改了 httpd.cong 文件 1。

AddHandler cgi-script .py
ScriptInterpreterSource Registry-Strict
  1. 添加
<IfModule dir_module>
    DirectoryIndex index.php index.pl index.cgi index.asp index.shtml index.html index.htm \
                   default.php default.pl default.cgi default.asp default.shtml default.html default.htm \
                   home.php home.pl home.cgi home.asp home.shtml home.html home.htm index.py
</IfModule>

也请检查我的代码

#!C:\Users\admin\AppData\Local\Programs\Python\Python37\python.exe

print('sarvesh')

#print(mycursor.rowcount, "record inserted.")

所以请告诉我。

看这里我的输出 在此处输入图像描述

标签: pythonserverlocalhostlocal

解决方案


您是否尝试放入 cgi-bin 文件夹?你能测试一下以确保你的安装没问题吗?你在使用任何放大器吗?( xampp, wamp)


推荐阅读