When the user clicks the login button, it should run a python file, which is a program that checks user login info. I'm very new to coding and html so I'm not quite sure if it's possible or not. CODE
from flask import Blueprint
auth = Blueprint("auth", __name__)
@auth.route('/login')
def login():
return "<p>Login</p>"
#Here is where I'd like to run the python script
@auth.route('/logout')
def logout():
return "<p>Logout</p>"
CodePudding user response:
It is possible to run a python file in html using PHP.
Write a PHP file as "index.php":
<html>
<head>
<title>RUN MY PYTHON FILES</title>
<?PHP
echo shell_exec("python test.py 'param1'");
?>
</head>
Passing the parameter to python, create a python as "test.py":
import sys
input=sys.argv[1]
print(input)
Print the parameter passed by PHP. If your parameter needs to support spaces, try doing this:
echo shell_exec("python test.py \"Param 1\"")
CodePudding user response:
You can just create a function and let it do what you want it to do:
def your_function():
# Put whatever it should do here
Then, when you want to run the code you wrote in your function, you can call it with. For example, if you want it to run in your login function, do this:
@auth.route('/login')
def login():
your_function()
return "<p>Login</p>"

