我是 python 新手,我正在尝试编写代码以在 oracle 时从数据库中获取数据以检查用户是否注册。此代码用于 Web 应用程序但它给出 403:Forbidden 错误。我无法确定代码中是否有问题或者它需要更多配置,我正在使用 Windows 7。
import logging
import tornado.escape
import tornado.ioloop
import tornado.options
import tornado.web
import tornado.websocket
import os.path
import uuid
import time
import cx_Oracle
from tornado.options import define, options
define("port", default=5000, help="run on the given port", type=int)
class Application(tornado.web.Application):
def __init__(self):
handlers = [(r"/", MainHandler),(r"/loggedin/page", UserIndex),]
settings = dict(
cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
xsrf_cookies=True,
autoescape=None,
)
tornado.web.Application.__init__(self, handlers, **settings)
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.render("mainPage.html")
class UserIndex(tornado.web.RequestHandler):
def post(self):
userid=self.get_argument('userid')
pwd=self.get_argument('pwd')
con=cx_Oracle.connect('system','system','localhost:1521/XE')
c=con.cursor()
coun=c.execute("select count(*) from dmsuser where email= '%s' and pwd ='%s'" %(userid,pwd))
con.close()
if coun.fetchone()==(1,):
self.render('loggedinPage.html')
else:
self.render('mainPage.html')
def main():
tornado.options.parse_command_line()
app = Application()
app.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
if __name__ == "__main__":
main()