У меня есть некоторый код Python ниже, который откроет существующую веб-страницу, если возникнет условиеК сожалению, код не отображает веб-страницу, которая была определена в скрипте Python как email.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, функция веб-браузера не открывает URL-адрес.
Кто-нибудь может объяснить, почему?Спасибо.