[英]Python CGI downloads the file instead of executing on CentOS
I have worked on CGI by python programming on Ubuntu and I got satisfied result. 我已经在Ubuntu上通过python编程来开发CGI,并且得到了满意的结果。 I have a HTML file that has a simple form with a simple input as button, and an action to
.py
file. 我有一个HTML文件,该文件具有简单的形式,带有作为按钮的简单输入以及对
.py
文件的操作。 the .py
file has 755
permission and is located in /var/www/cgi-bin
. .py
文件具有755
权限,位于/var/www/cgi-bin
。 and the HTML is located in /var/www/html
. 并且HTML位于
/var/www/html
。 I run the CGIHTTPServer
by executing the following command in /var/www/
directory. 我通过在
/var/www/
目录中执行以下命令来运行CGIHTTPServer
。 But when I click the button, the browser instead of executing the .py
file, tries to download it and it's annoying me. 但是,当我单击该按钮时,浏览器而不是执行
.py
文件,而是尝试下载该文件,这很烦我。 I tried to reconfigure http.conf
file with <Directory></Directory>
tag of cgi-bin
many times but no result! 我试图用
cgi-bin
<Directory></Directory>
标记重新配置http.conf
文件很多次,但是没有结果! Please HELP ME!!!! 请帮我!!!!
#!/usr/bin/env python2
import cgi
import cgitb; cgitb.enable()
from MySQLdb import *
# Creates a connection with database
dbconnection = connect(host="localhost", user="root", passwd="", db="testdb")
# Creates a cursor of db
cursor = dbconnection.cursor()
# Selects data from database
cursor.execute("SELECT * FROM inp;")
# HTML view by printing codes as strings
print("Content-type: text/html\r\n\r\n")
print("")
print("<html>")
# Body of HTML Page
print("<body>")
print("<h1>بانک اطلاعاتی!</h1>")
# A table that shows the database
print("<table>")
print("<th>ID</th><th>input</th>")
for row in cursor.fetchall():
print("<tr>")
print("<td>" + str(row['ID']) + "</td>")
print("<td>" + str(row['inpt']) + "</td>")
print("</tr>")
print("</table>")
# End of HTML
print("</body></html>")
<html>
<head>
<meta charset='utf-8' />
</head>
<style>
body { background: #ececec; }
body, p { text-align: center; direction: rtl; }
</style>
<body>
<h1>نمای وبگونه از بانک اطلاعاتی</h1>
<p>دکمه زیر را فشار دهید تا بانک اطلاعاتی را مشاهده نمائید!</p>
<form action="/cgi-bin/show_database.py">
<input type="Submit" value="مشاهدهی بانک" name="data">
</form>
</body>
</html>
Are you running the html file like hhtp://localhost/display_databse.html
? 您是否正在运行像
hhtp://localhost/display_databse.html
这样的html文件? Well if its still not working you can try XAMPP .Its hassle free to setup the same apache server with mariadb/php for home/testing usage but needs some tweaking for production. 好吧,如果它仍然无法正常工作,您可以尝试XAMPP。它可以轻松地使用mariadb / php设置相同的apache服务器,以用于家庭/测试用途,但需要进行一些调整以进行生产。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.