[英]Functions are not being called when Python variables are passed into HTML
#!/usr/bin/env python3
import cgi
import sqlite3
import os
path = '/var/www/html/mahesh1/trishul.db'
con = sqlite3.connect(path)
cur = con.cursor()
form = cgi.FieldStorage()
print("Content-Type:text/html\n\n")
cur.execute("SELECT * from staff")
p = cur.fetchall()
global NAME
global EMAIL
def ins():
global to
print(to)
cur.execute("UPDATE staff SET password=? WHERE email_id=?", (rnd,to))
con.commit()
def rand():
global rnd
rnd = ''.join(random.choice('0123456789ABCDEF') for i in range(random.choice([6,7,8,9,10])))
def email(to):
fromaddr = "dummy.trishul@gmail.com"
fpwd = "bilbobaggins"
body = 'Dear Student, your password has been set to '+rnd+'. Please Login with this password.'
subj = "Password Issue"
print(to)
yag = yagmail.SMTP(fromaddr, fpwd).send(to, subj, body)
for i in p:
NAME = i[1]
EMAIL = i[2]
html1 = '''
<html>
<head>
<style>
table {
border-collapse: collapse;
width: 1368;
}
td {
text-align:center;
padding: 8px;
}
tr:nth-child(even){background-color: #f2f2f2}
th {
text-align:center;
padding: 8px;
background-color: #4CAF50;
color: white;
}
div{
padding-right:0px;
}
div{
color: #FF0000
}
</style>
</head>
<body>
<form>
<table>
<tr>
<td>%s</td>
<td>%s</td>
<td><input type='submit' name='%s' value='APPROVE'></td>
</tr>
</table>
</form>
</body>
</html>'''%(NAME,EMAIL,EMAIL)
if NAME in form:
rand()
email(EMAIL)
ins()
print(html1)
Functions are not being called. 未调用函数。 I am displaying the name, email and approve button on the HTML page from my database through the path. 我正在通过路径从数据库中的HTML页面上显示名称,电子邮件和批准按钮。 When I click the approve button to a particular email id and name on my HTML page it should send the mail to the respective email id. 单击我的HTML页面上的特定电子邮件ID和名称的批准按钮时,它应将邮件发送到相应的电子邮件ID。
In your form, you have no action specified. 在您的表单中,您未指定任何操作。 <form action='myscript.py'>
sends the request to that script, and the server will execute the script giving it the form data as arguments. <form action='myscript.py'>
将请求发送到该脚本,服务器将执行脚本,并为其提供表单数据作为参数。 (Copied from my comment above) (摘自我上面的评论)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.