我正在创建一个 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()