[英]How can my PHP code run when i submit a HTML form
I am trying to make a website using python and in flask I have a webpage that has a submit button, when the button is pressed I need it to run a python file I have called Answers.py我正在尝试使用 python 创建一个网站,在 Flask 中,我有一个带有提交按钮的网页,当按下按钮时,我需要它来运行一个名为 Answers.py 的 python 文件
from flask import Flask, request, render_template, send_from_directory
app = Flask(__name__)
@app.route('/help', methods=["GET","POST"])
def help():
return render_template("help.html")
the HTML code on the page is this and i am trying to get when the button is pressed it runs a php script that outputs the value from a separate python file, the output text.页面上的 HTML 代码是这样的,我试图在按下按钮时获取它运行一个 php 脚本,该脚本从单独的 python 文件输出值,即输出文本。
<html>
<body>
<form action="" method="post">
<button type="submit" name="sub" value="Hello world">Submit
call</button>
</form>
</body>
</html>
I have tried this php code in the same file as the HTML but nothing is output when I press the button, i'm new to php so i'm not sure what the problem is.我已经在与 HTML 相同的文件中尝试过这个 php 代码,但是当我按下按钮时没有任何输出,我是 php 新手,所以我不确定问题是什么。
<?php
if(isset($_POST['sub']))
{
$result = exec("Python Path Answers.py /tmp");
echo $result;
}
?>
The php script never gets referenced in the html page! php 脚本永远不会在 html 页面中被引用!
<form action="" method="post"><!-- action there is empty! -->
You should reference the php script in the action
attribute of the <form>
tag, like so:您应该在
<form>
标签的action
属性中引用 php 脚本,如下所示:
<form action="myscript.php" method="post">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.