在索引.html公司名称:
<html>
<head>
<title>Login Page</title>
<link type="text/css" rel="stylesheet" href="coach.css" />
</head>
<body>
<img src="images/logo-cel-transparent_0.png" width="74" height="64"><strong><img src="images/logo-cel-transparent_0.png" alt="Cel logo" width="74" height="64" align="right">
</strong>
<h1 align="center"><strong>Central Electronics Limited</strong></h1>
<p> </p>
<h2 align="center">Storage Management System</h2>
<p> </p>
<p align="center">Login To System</p>
<p align="center"> </p>
<form action="cgi-bin/validate.py" method="post">
<div align="center">Username :
<input type="text" name="username">
<br>
Password :
<input type="text" name="password">
<br>
<input type="submit" value="Submit">
</div>
</form>
<p align="center"> </p>
</body>
</html>
在验证.py公司名称:
^{pr2}$在成功验证.py公司名称:
import yate
print(yate.start_response())
print(yate.para("Login Successful"))
print(yate.include_footer({"Click here to Go to Welcome Page":"/welcome.html"}))
简单_httpd.py公司(服务器代码):
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()
我运行服务器(简单_httpd.py公司)使用命令提示符。索引页打开。我输入第一组用户名和密码。它按预期运行并且成功验证.py打开。但是当我输入第二组用户名和密码时(即,第二行表validate in用户.sqlite)(validate表包含两组用户名和密码),它显示在cmd上:
127.0.0.1 - - [18/Jun/2015 20:59:29] b'Traceback (most recent call last):\r\n F
ile "C:\\Python34\\ProjectShivam\\webapp\\cgi-bin\\validate.py", line 25, in <mo
dule>\r\n password1=[row[0] for row in pass_result.fetchall()]\r\nNameError:
name \'pass_result\' is not defined\r\n'
另外,任何其他用户名都不会导致在web浏览器上打印“登录失败”文本,而是在服务器上显示相同的错误。怎么了?在
当不满足此条件时,您将收到错误:
设置一个默认值来传递结果,例如
pass_result = None
,然后在使用之前处理它,例如if pass_result is not None:
相关问题 更多 >
编程相关推荐