我正在使用python web.py框架设计一个小型Web应用程序,以下是我的index.py代码
index.py
import web
from web import form
import MySQLdb as mdb
render = web.template.render('templates/')
urls = (
'/', 'Login',
'/projects', 'Projects',
)
app = web.application(urls, globals())
conn = mdb.connect(user='root', passwd='redhat', db='Python_Web', host='localhost')
class Login:
login_form = form.Form(
form.Textbox('username', form.notnull),
form.Password('password', form.notnull),
form.Button('Login'),
)
def GET(self):
form = self.login_form()
return render.login(form)
def POST(self):
if not self.login_form.validates():
return render.login(self.login_form)
i = web.input()
username = i.username
password = i.password
query = "select user_login,user_password from user where user_login = '%s' " % username
cur = conn.cursor()
cur.execute( query )
user_details = cur.fetchone()
if username == user_details[0] and password == user_details[1]:
raise web.seeother('/projects')
else:
return render.login_error(form)
if __name__ == "__main__":
web.internalerror = web.debugerror
app.run()
当我localhost:8080 在浏览器中运行上述文件时,我可以看到登录页面,其中包含代码login.html并以方式访问render.login(form),
但是当用户名和密码匹配时,我的目的是重定向到另一页(projects.py),并按web.seeother('/projects')上述方式编写。现在,这将进入projects类并显示该类的html页面
但是当我单击登录按钮时,我看到以下错误
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/web/application.py", line 239, in process
return self.handle()
File "/usr/lib/python2.7/site-packages/web/application.py", line 230, in handle
return self._delegate(fn, self.fvars, args)
File "/usr/lib/python2.7/site-packages/web/application.py", line 420, in _delegate
return handle_class(cls)
File "/usr/lib/python2.7/site-packages/web/application.py", line 396, in handle_class
return tocall(*args)
File "/home/local/usser/python_webcode/index.py", line 55, in GET
app.run()
File "/usr/lib/python2.7/site-packages/web/template.py", line 881, in __call__
return BaseTemplate.__call__(self, *a, **kw)
File "/usr/lib/python2.7/site-packages/web/template.py", line 808, in __call__
return self.t(*a, **kw)
TypeError: __template__() takes exactly 1 argument (0 given)
谁能帮我解决以上错误
另外在web.py中如何重定向到另一个具有html文件链接的类
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。