我是python中的新手我正在尝试编写代码来从数据库中获取数据,而oracle则检查用户是否注册。此代码适用于Web应用程序但是它给出了403:Forbidden Error。我无法确定是否代码中的问题或者它需要更多配置我在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()
答案 0 :(得分:1)
如果没有模板,我无法确定,但我的猜测是你没有在POST请求中包含XSRF数据。由于您已在应用配置中设置xsrf_cookies=True
,因此您需要在表单模板中包含xsrf数据:
<form method="post" action="...">
{% module xsrf_form_html() %}
...
</form>