我正在基于用户选择的json文件创建一个d3可视化,如下所示-
d3.json("/data", function(error, graph)
这是views.py 中的应用程序路线
@app.route("/data") #the javascript will call this
def data():
return(userInput.get_data()) #returns the return value of given function
在表单中,我有一个userInput类,它包含一个下拉列表。该列表由json文件的名称组成。json_fileCrew是用户选择的json文件的名称。
json_fileCrew = SelectField(u"Filename", choices=[(f, f) for f in filenamesCrew])
在这个类中,我有get_data函数:
def get_data(json_fileCrew):
return send_from_directory ("/project/myproject/app/static/Crews" , json_fileCrew)
因此,当javascript调用/data时,它应该返回json_fileCrew,但我得到了这个错误
File "projectmyprojectappviews.py", line
34, in data
return(userInput.get_data()) #returns the return value of given function
TypeError: get_data() missing 1 required positional argument: 'json_fileCrew'
这是完整的Traceback-
Traceback (most recent call last):
File "C:Python34libsite-packagesflaskapp.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "C:Python34libsite-packagesflaskapp.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "C:Python34libsite-packagesflaskapp.py", line 1403, in handle_except
ion
reraise(exc_type, exc_value, tb)
File "C:Python34libsite-packagesflask_compat.py", line 33, in reraise
raise value
File "C:Python34libsite-packagesflaskapp.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "C:Python34libsite-packagesflaskapp.py", line 1477, in full_dispatch
_request
rv = self.handle_user_exception(e)
File "C:Python34libsite-packagesflaskapp.py", line 1381, in handle_user_e
xception
reraise(exc_type, exc_value, tb)
File "C:Python34libsite-packagesflask_compat.py", line 33, in reraise
raise value
File "C:Python34libsite-packagesflaskapp.py", line 1475, in full_dispatch
_request
rv = self.dispatch_request()
File "C:Python34libsite-packagesflaskapp.py", line 1461, in dispatch_requ
est
return self.view_functions[rule.endpoint](**req.view_args)
File "projectmyprojectappviews.py", line
34, in data
return(userInput.get_data()) #returns the return value of given function
TypeError: get_data() missing 1 required positional argument: 'json_fileCrew'
您有一个方法
def get_data(json_fileCrew)
但你并没有用必需的参数来调用它
return(userInput.get_data())
因为错误告诉你
TypeError: get_data() missing 1 required positional argument: 'json_fileCrew'