0

我正在创建一个 webpy 应用程序,该应用程序具有多个接受输入的表单,并且该输入由 python 执行,但是我在第一个表单上的键错误上不断收到属性错误:AttributeError : 'Pycode',不知道为什么会这样,这是代码:

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()
4

1 回答 1

0

检查如何使用表单输入的文档。每个输入都应该有 name 作为它的第一个参数,你的name属性应该是description.

于 2012-08-03T07:41:43.587 回答