Create the following html. Prepare a python program that returns the entered value when you enter it.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>test</h1>
<p>Please enter the characters</p>
<input id="plane" type="text" value="">
<input id="btn" type="button" value="input">
<p id="string"></p>
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script>
$(function(){
$("#btn").click(
function() {
var plane = document.getElementById("plane").value;
$.ajax({
url: "./test.py",
type: "post",
data: {data: plane},
success: function(data){
document.getElementById("string").innerText = data;
},
error: function(data){
console.log("failed");
}
});
}
);
});
</script>
</body>
</html>
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import cgi
storage = cgi.FieldStorage()
data = storage.getvalue('data')
print('Status: 200 OK')
print('Content-type: text/html\n')
print('The entered characters are' + data + 'is.')
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ sudo -i
[root@ip-xxx-xxx-xxx-xxx ~]# yum install python3
[root@ip-xxx-xxx-xxx-xxx ~]# yum install httpd
[root@ip-xxx-xxx-xxx-xxx ~]# systemctl start httpd
[root@ip-xxx-xxx-xxx-xxx ~]# cd /var/www/html/
[root@ip-xxx-xxx-xxx-xxx html]# vi index.html
[root@ip-xxx-xxx-xxx-xxx html]# vi test.py
[root@ip-xxx-xxx-xxx-xxx html]# chmod 775 test.py
[root@ip-xxx-xxx-xxx-xxx html]# vi /etc/httpd/conf/httpd.conf
Add ExecCGI at the end of line around line 144 Options Indexes FollowSymLinks ExecCGI
Add a line around line 157 AddHandler cgi-script .cgi .py
At the end of line around line 306.html .Add htm AddType text/html .shtml .html .htm
At the end of line around line 307.html .Add htm AddOutputFilter INCLUDES.shtml .html .htm
[root@ip-xxx-xxx-xxx-xxx html]# systemctl restart httpd
Recommended Posts