def machines(machine_name):
rb = np.array(machines_file.loc[machines_file['Machine'].str.contains(machine_name), 'Resolved By'])
rb_o = np.count_nonzero(rb == 'Outsource')
rb_ih = np.count_nonzero(rb == 'In-House')
return render_template('reachtruck.html',outsource=rb_o, inhouse=rb_ih)
#Passing a keyword for the argument of above funtion
@app.route('/home/reach_truck')
machines('Reach Truck')
The code is showing error of indentation when I am passing the keyword under the flask decorator
CodePudding user response:
The decorator goes on the function definition, not the function call:
@app.route('/home/reach_truck')
def machines(machine_name):
rb = np.array(machines_file.loc[machines_file['Machine'].str.contains(machine_name), 'Resolved By'])
rb_o = np.count_nonzero(rb == 'Outsource')
rb_ih = np.count_nonzero(rb == 'In-House')
return render_template('reachtruck.html',outsource=rb_o, inhouse=rb_ih)
machines('Reach Truck')
If you want to only apply the decorator to that specific invocation of the function, don't use the decorator syntax, just call it as a normal function (note: I'm not a Flask expert but I don't think app.route
will work as intended if you call it this way):
app.route('/home/reach_truck')(machines)('Reach Truck')
CodePudding user response:
decorator is basically a function. Just pass to it
app.route('/home/reach_truck')(machines)('Reach Truck')