网络浏览器打开()在调用html中的python脚本文件时不显示网页

2024-04-20 03:11:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我下面有一些python代码,如果出现这种情况,它将打开一个exist网页。。你知道吗

我在IDLE中尝试过这段代码,它工作得很好,但是当我在html代码中调用python文件时,不幸的是,它没有显示python脚本中定义的web页面电子邮件.html... 你知道吗

#!c:\python\python.exe
# Import modules for CGI handling 
import cgi, cgitb , json
import string
#import random
#import smtplib
import webbrowser
import threading

print ("Content-type:text/html\r\n\r\n")
# Create instance of FieldStorage 
fo = cgi.FieldStorage() 

# Get data from fields
fmail = fo.getvalue('cmail')
fpassw = fo.getvalue('cpasw')

webadrs = "http://localhost:8080/email.html"

from ConnectDB import mydb
mycursor = mydb.cursor(buffered=True)
try:
    mycursor.execute("""SELECT * FROM register WHERE ((emailh = %s ) AND ( password = %s))""",( fmail,fpassw))

    myresult = mycursor.fetchall()

    if (len(myresult) == 0):

        print("This user name or password not defined..!")
    else:
        webbrowser.open(webadrs)


except:
   # Rollback in case there is any error
   mydb.rollback()

mydb.close()



   <!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
    <meta charset="utf-8">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>

</head>
<body>
   <form action = "/python/runwpage.py" method = "post">
Mail: <input type = "text" name='cmail'>  <br>

Password: <input type = "password" name= 'cpasw' />
<input type = "submit" value = "Submit" />
</form>

</body>
</html>

实际上,如果len(myresult) == 0,我可以得到第一个输出。但是当它不等于0时,webbrowser函数不会打开url。你知道吗

有人能解释为什么吗?谢谢。你知道吗


Tags: 代码textnameimportinputhtmltypepassword