Web.py 表单未发布?
我根据我发现的几个不同的 web.py 示例编写了以下内容,但我无法发布登录页面,有什么想法为什么我的代码如此 foobar 吗?
ps 另外,如果我想使用会话,为什么似乎必须将 web.config.debug 设置为 false?
import web
import db
from web import form
login = form.Form(
form.Textbox('username'),
form.Password('password'),
form.Button('Login'), )
urls = (
'/', 'Index',
'/login', 'Login',
'/home', 'Home', )
web.config.debug = False
app = web.application(urls, globals())
session = web.session.Session(app, web.session.DiskStore('sessions'))
class Login:
def GET(self):
f = login()
return render.register(f)
def POST(self):
f = web.input()
check = db.db_query('select * from users where username=? and password=?', (i.username, i.password))
if check:
session.loggedin = True
session.username = i.username
raise web.seeother('/home')
else: return render.base("Those login details don't work.")
class Index:
def GET(self):
return 'index'
class Home:
def GET(self):
return 'home'
if __name__ == '__main__':
app.run()
I wrote the following based on a few different web.py examples I found, but im unable to get the login page to post, Any ideas why my code is sooo foobar?
p.s also why does it seem that I have to have web.config.debug set to false if I want to use sessions?
import web
import db
from web import form
login = form.Form(
form.Textbox('username'),
form.Password('password'),
form.Button('Login'), )
urls = (
'/', 'Index',
'/login', 'Login',
'/home', 'Home', )
web.config.debug = False
app = web.application(urls, globals())
session = web.session.Session(app, web.session.DiskStore('sessions'))
class Login:
def GET(self):
f = login()
return render.register(f)
def POST(self):
f = web.input()
check = db.db_query('select * from users where username=? and password=?', (i.username, i.password))
if check:
session.loggedin = True
session.username = i.username
raise web.seeother('/home')
else: return render.base("Those login details don't work.")
class Index:
def GET(self):
return 'index'
class Home:
def GET(self):
return 'home'
if __name__ == '__main__':
app.run()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请检查此处提供的示例( http://webpy.org/cookbook/forms ),对我来说似乎仅仅执行 form.Form(...) 并没有真正创建标签,所以请检查您的输出 HTML。
基本上它缺少
包含您的元素(文本输入、按钮)
Please check the example presented here ( http://webpy.org/cookbook/forms ), to me it seems that just doing form.Form(...) doesn't actually create the tag, so please check your output HTML.
Basically it's missing
<form name="main" method="post"> ... </form>
encompassing your elements (textinput, button)您正在使用未定义的“i”变量...尝试使用您为 web.input() 定义的变量“f”
You're using 'i' variable which was not defined...try using the 'f' the one you defined for web.input()