Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Javascript中调用Python函数,读取静态文件(Flask)_Javascript_Python_Json_Flask - Fatal编程技术网

在Javascript中调用Python函数,读取静态文件(Flask)

在Javascript中调用Python函数,读取静态文件(Flask),javascript,python,json,flask,Javascript,Python,Json,Flask,我正在创建一个基于用户选择的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 在表单中,我有一

我正在创建一个基于用户选择的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_文件组,但我得到了这个错误

File "\project\myproject\app\views.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 (most recent call last):
  File "C:\Python34\lib\site-packages\flask\app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Python34\lib\site-packages\flask\app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "C:\Python34\lib\site-packages\flask\app.py", line 1403, in handle_except
ion
    reraise(exc_type, exc_value, tb)
  File "C:\Python34\lib\site-packages\flask\_compat.py", line 33, in reraise
    raise value
  File "C:\Python34\lib\site-packages\flask\app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Python34\lib\site-packages\flask\app.py", line 1477, in full_dispatch
_request
    rv = self.handle_user_exception(e)
  File "C:\Python34\lib\site-packages\flask\app.py", line 1381, in handle_user_e
xception
    reraise(exc_type, exc_value, tb)
  File "C:\Python34\lib\site-packages\flask\_compat.py", line 33, in reraise
    raise value
  File "C:\Python34\lib\site-packages\flask\app.py", line 1475, in full_dispatch
_request
    rv = self.dispatch_request()
  File "C:\Python34\lib\site-packages\flask\app.py", line 1461, in dispatch_requ
est
    return self.view_functions[rule.endpoint](**req.view_args)
  File "\project\myproject\app\views.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'

那么,错误回溯是很明显的:您在调用函数
get\u data
时没有使用所需的参数
json\u fileCrew
。问题是什么?您的
.get_data()
函数是用参数定义的,但是您的代码没有传递参数。谢谢,我花了这么多时间看了一件我没有注意到的错误的东西,结果答案就在我面前!