This is validate.py
import cgi
import yate
import sqlite3
connection = sqlite3.connect('users.sqlite')
cursor = connection.cursor()
print(yate.start_response('text/plain'))
form=cgi.FieldStorage()
for each_form_item in form.keys():
if (each_form_item=='username'):
username=form[each_form_item].value
if (each_form_item=='password'):
password=form[each_form_item].value
result=cursor.execute('SELECT USERNAME from validate')
usernames=[row[0] for row in result.fetchall()]
for each_username in usernames:
if (username==each_username):
pass_result=cursor.execute('SELECT PASSWORD from validate where username=?',(each_username,))
password1=[row[0] for row in pass_result.fetchall()]
for each_password in password1:
if (each_password==password):
print('Login Success')
#Here want to run another python program eg welcome.py
else:
print('Login Failure')
web服务器正在后台运行。如果上面代码中的条件为真,我想将网页重定向到另一个python程序。我该怎么做?在
编辑:
在索引.html在
^{pr2}$
当我点击提交按钮时验证.py跑。现在,如果用户名和密码匹配,我希望web浏览器自动将浏览器重定向到另一个py文件或html页面,而不需要用户做任何事情。在
编辑2:
我使用的python服务器的代码是:from http.server import HTTPServer, CGIHTTPRequestHandler
port = 8080
httpd = HTTPServer(('', port), CGIHTTPRequestHandler)
print("Starting simple_httpd on port: " + str(httpd.server_port))
httpd.serve_forever()
这是使用命令提示符运行的。然后使用“在web浏览器中打开索引页”本地主机:8080". 在