Python 3.x Python脚本以html格式处理并生成结果。我想用WSGI在网上发布

Python 3.x Python脚本以html格式处理并生成结果。我想用WSGI在网上发布,python-3.x,web-applications,python-requests,mod-wsgi,Python 3.x,Web Applications,Python Requests,Mod Wsgi,如何从myapp.wsgi调用现有的testreport.py。 py进程DB以HTML格式获取结果 myapp.wsgi **testreport.py** def getFormattedMailBody(data,color,frm,to): htable ="""<html> <b>Bp Report for %s to %s.</b> <br /> <br /><table style=\

如何从myapp.wsgi调用现有的testreport.py。 py进程DB以HTML格式获取结果

myapp.wsgi

**testreport.py**

def getFormattedMailBody(data,color,frm,to):
    htable ="""<html>
        <b>Bp Report for %s to %s.</b> <br />
    <br /><table style=\"border: 3px solid olive;\" border=1>
    <tr style=\"background-color:%s; color:white;\">
        <td><b>S. No.</b></td><td><b> Business </b></td><td><b> DB Name / Tags </b></td><td><b> AWS ID </b></td><td><b> AWS DB InstanceIP </b></td><td><b> Backup / AMI ID </b></td><td><b> Start Date & Time
        </b></td><td><b> End Date & Time </b></td><td><b>Tentative Time Taken to backup AMI</b></td><td><b> Backup Copies </b></td><td><b>Group Name</b></td><td><b>Owner</b></td><td><b>Mailing List</b></td><td><b>Tagname</b></td></tr>"""%(frm,to,color)

    #htable=u'<table border="1" bordercolor=000000 cellspacing="0" cellpadding="1" style="table-layout:fixed;vertical-align:bottom;font-size:13px;font-family:verdana,sans,sans-serif;border-collapse:collapse;border:1px solid rgb(130,130,130)" >'
#    data[0] = ['<b>' + datetime.datetime.strptime(i, '%m/%d/%y %H:%M:%S') + u'</b>' for i in data[0]] 
    n=1
    for row in data:
            newrow = '<tr style=\"color:%s;\"><td>%s </td>'%(color,n)
        newrow = newrow + ''.join([u'<td align="right" style="padding:1px 4px">' + unicode(x) + u'</td>' for x in row])
        newrow += '</tr>'
        htable+= newrow
        n+=1
    htable += '</table></html>'
    return htable

这段代码显示了testreport如何从db中获取记录,然后在html中处理它,从testreport.py中导入所需的任何函数/变量/类,并在其他python脚本中调用该函数。从您显示的代码中不清楚您尝试在何处使用testreport.py以及确切的问题是什么。当我打开在网页上获得的url时使用上述内容:欢迎使用mod_wsgi测试页。我想要的是在网页上使用我的testreport.py的输出。在testreport.py>>中,访问mysql获取表,然后创建html尝试在Web上发送此邮件您的帖子被标记为“django”,所以我想您使用的是django,但看起来您根本没有使用django,是吗?无论如何,您有一个返回HTML的函数,因此您可以编写一个django视图,调用该函数并在
HttpResponse
中返回该HTML。如果您不使用django,但只希望您的wsgi脚本返回HTML,那么只需替换默认wsgi.py中的部分(您从问题中删除了该部分)通过调用函数来创建html。
def send_mail(grpname,rows,receiver):
        datefrom=dt.date.today()-dt.timedelta(days=2)
        dateto=dt.date.today()-dt.timedelta(days=1)
        html=getFormattedMailBody(rows,Color("green"), datefrom, dateto)
        print(html)

def query_mysql(procedurename):
        try:
                conn = mysql.connector.connect( host=hostname, port=port, database=database, user=username, password=password)
                cur = conn.cursor()
                cur.callproc(procedurename)
                cur.stored_results()
                for result in cur.stored_results():
                        global results1
                        results1 = result.fetchall()
                header1 = [i[0] for i in result.description]
                rows1 = [list(i) for i in results1]
                cur.close()
                conn.close()
                return rows1

        except Error as e:
                print(e)

def sort_on_groups(rows):

        groups=[]
        for row in rows:
                if row[9] not in groups:
                        groups.append(row[9])

        mail='i@.com'
        send_mail('In',rows,mail)

a=query_mysql('reportdata')

html=sort_on_groups(a)