webpy中具有多个表单的属性错误

时间:2012-08-02 18:32:21

标签: python forms web.py

我正在创建一个webpy应用程序,其中有多个表单需要输入,而输入是由python执行的,但是我在第一个表单上的键错误上不断出现属性错误: AttributeError:'Pycode'< / strong>,不知道为什么会发生这种情况,这是代码:

import web
from Commands import *
import Commands

operations = [method for method in dir(port) if callable(getattr(port, method))]
test = port(0)

def make_text(string):
    return string

urls = ('/', 'tutorial')
render = web.template.render('templates/',globals={'oper':operations})

app = web.application(urls, globals())

pythonCode = web.form.Form(
            web.form.Textarea(name='', class_='Pycode', id='Pycode')
            )
setProportionalGain = web.form.Form(
    web.form.Textbox(name='Set Proportional Gain', class_='SG', id='SG')
    )
setIntegralGain = web.form.Form(
    web.form.Textbox(name='Set Inegral Gain', class_='SI', id='SI')
    )
setDerivativeGain = web.form.Form(
    web.form.Textbox(name='Set Derivative Gain', class_='SD', id='SD')
    )

class tutorial:
    def GET(self):
        code = pythonCode()
        proportional = setProportionalGain()
        integral = setIntegralGain()
        derivative = setDerivativeGain()
    return render.tutorial(code,proportional,integral,derivative, "Input Command for ohm")

def POST(self):
    form = pythonCode()
    proportional = setProportionalGain()
    integral = setIntegralGain()
    derivative = setDerivativeGain()
    form.validates()
    data = web.input()
    print data
    print data.Pycode
    s = data.Pycode
    proportionalGain = "test.setProportionalGain(%s)" % data.SG
    integralGain = "test.setItegralGain(%s)" % data.SI
    derivativeGain = "test.setDerivativeGain(%s)" % data.SD
    try:
        exec(proportionalGain)
        exec(integralGain)
        exec(derivativeGain)
        exec(data.Pycode)
        s = "This is Python!"
    except:
        pass
    return s


if __name__ == '__main__':
    app.run()

1 个答案:

答案 0 :(得分:0)

查看how to use form inputs的文档。每个输入都应该有名称作为第一个参数,而name属性中的内容应该是description