我正在尝试将Web表单的内容放到python脚本中。我使用下面的代码,当我点击提交时,我必须在网页上看到输出。基本上你好,(取自网页作为输入)。我遇到了类型错误。
#!/bin/python
import os
from flask import Flask
from flask import request
from flask import render_template
app = Flask(__name__)
@app.route('/')
def my_form():
return render_template("index.html")
@app.route('/', methods=['POST'])
def my_form_post():
text = request.form['text']
cmd = "sh relay.sh " + text
rep = os.system(cmd)
return rep
if __name__ == '__main__':
app.run()
运行时出现以下错误。我基本上试图从网页(文本框)传递一些信息。我刚刚进入了Damnnn'检查输出。
Hello, Damnnn
10.x.x.x - - [19/Jan/2017 0227:11:51] "POST / HTTP/1.1" 500 -
Traceback (most recent call last):
File "/usr/lib64/python2.7/site-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/lib64/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "/usr/lib64/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib64/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib64/python2.7/site-packages/flask/app.py", line 1615, in full_dispatch_request
return self.finalize_request(rv)
File "/usr/lib64/python2.7/site-packages/flask/app.py", line 1630, in finalize_request
response = self.make_response(rv)
File "/usr/lib64/python2.7/site-packages/flask/app.py", line 1740, in make_response
rv = self.response_class.force_type(rv, request.environ)
File "/usr/lib/python2.7/site-packages/werkzeug/wrappers.py", line 911, in force_type
response = BaseResponse(*_run_wsgi_app(response, environ))
File "/usr/lib/python2.7/site-packages/werkzeug/test.py", line 884, in run_wsgi_app
app_rv = app(environ, start_response)
TypeError: 'int' object is not callable
对不起,我是python的新手。
答案 0 :(得分:1)
你要返回的对象是一个int,试着像这样强制转换为字符串。
return str(rep)