简体   繁体   English

将Python变量传递到HTML时未调用函数

[英]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.

相关问题 Sqlite 中的变量被传递到 function 时执行(Python3) - Variables in Sqlite execution when being passed into a function (Python3) 局部变量未传递给单独加载的 class - python3 中定义的函数 - Local variables not being passed to functions defined within a separately loaded class - python3 在Python中使用self时,为什么将传递给函数的类在类函数内部调用? - Why is the class passed to a function being called inside a class function when using self in Python? 为什么我的 python 函数被调用了两次? - Why are my python functions being called twice? 将HTML内的Python代码与传入的变量相结合 - Combining Python code inside HTML with variables passed in 当 python 脚本在 Z2591C98B70119FE62489Z 脚本 BEE4 - Pass the variables from python script to shell script when python script is being called inside shell script 传递时未解析Python参数 - Python arguments not being parsed when passed 蟒蛇。 为什么我传递的变量没有被更新? 他们不是通过引用传递的吗? - Python. How come my passed variables aren't being updated? Aren't they being passed by reference? Python:对传递给函数的变量执行的操作不正确 - Python: Operations done on variables passed into functions aren't working right 没有按顺序调用函数? - Functions not being called in order?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM