简体   繁体   English

如何解决在本地运行我的 python 代码?

[英]How can I solve to run my python code run localy?

I already install python 3.7 version.我已经安装了 python 3.7 版本。 and when I run in command then its works great.当我在命令中运行时,它的效果很好。 But when I try to run http.server 8000 and then browse url then just display my index.py code not a run like web page.但是当我尝试运行 http.server 8000 然后浏览 url 然后只显示我的 index.py 代码而不是像 web 页面这样的运行。

Any idea for this.对此有任何想法。

I did change in httpd.cong file 1.我确实更改了 httpd.cong 文件 1。

AddHandler cgi-script .py
ScriptInterpreterSource Registry-Strict
  1. add添加
<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>

also please check my code也请检查我的代码

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

print('sarvesh')

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

so please let me know.所以请告诉我。

See here My output看这里 我的 output 在此处输入图像描述

Did you try to put in cgi-bin folder?您是否尝试放入 cgi-bin 文件夹? Could you test to make sure your installation is all right?你能测试一下以确保你的安装没问题吗? Are you using any amp?你在使用任何放大器吗? ( xampp, wamp) (xampp,wamp)

Try this: Create a folder called test.试试这个:创建一个名为 test 的文件夹。 open a command ("cmd.exe") in windows and enter the folder you created.在 windows 中打开命令(“cmd.exe”)并输入您创建的文件夹。 ex " cd c:\test ".例如“ cd c:\test ”。 Create a cgi-bin folder.创建一个 cgi-bin 文件夹。 ex " mkdir cgi-bin " run python embedded server. ex " mkdir cgi-bin " 运行 python 嵌入式服务器。 " python3 -m http.server --cgi " Put your code in the cgi-bin folder. " python3 -m http.server --cgi " 把你的代码放在 cgi-bin 文件夹中。 Access from the browser http://127.0.0.1:8000/cgi-bin/index.py从浏览器访问http://127.0.0.1:8000/cgi-bin/index.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM