无法从同一python文件的另一个烧瓶方法调用烧瓶方法



无法从同一python文件的另一个flask方法调用flask方法。例如,考虑下面的代码

@app.route('/api/v1/employee/add', method = ['POST'])
def add_employee():
req = request.json
#add the employee to db
@app.route('/api/v1/employee', method = ['GET'])
def get_employee():
data = json.loads(employee) #getting employee details from db
add_employee() # unable to call this method as I am getting the data as null.

如何解决这个问题

Flask函数将期望一个http请求。您可以在没有Flask app.route装饰器的情况下创建命令函数。这将有助于分离功能和http请求。例如:

def add_employee():
# Add Some Query here
pass

@app.route('/api/v1/employee/add', method = ['POST'])
def http_employee():
req = request.json
add_employee()

@app.route('/api/v1/employee', method = ['GET'])
def get_employee():
data = json.loads(employee) #getting employee details from db
add_employee() # unable to call this method as I am getting the data as null.

相关内容

  • 没有找到相关文章

最新更新