I need to change a ruby code to python and I am also new to this. Can someone tell me is there any function like before_action ... only: in python flask? This is the function I want to change:
class IftttController < ActionController::Basebefore_action :return_errors_unless_valid_service_keybefore_action :return_errors_unless_valid_action_fields, only: :create_new_thingdef return_errors_unless_valid_service_keyunless request.headers["HTTP_IFTTT_SERVICE_KEY"] == IFTTT_SERVICE_KEYreturn render plain: { errors: [ { message: "401" } ] }.to_json, status: 401endenddef return_errors_unless_valid_action_fieldsif params[:actionFields] && params[:actionFields][:invalid] == "true"return render plain: { errors: [ { status: "SKIP", message: "400" } ] }.to_json, status: 400endend
end
And as I read on internet, @app.before_request is equal to it, but I don't how to use it for specific action (before_action :return_errors_unless_valid_action_fields, only: :create_new_thing) like on the ruby on rails, Here is my code, I don't know whether it correct or not:
@ifttt.before_request
def return_errors_unless_valid_action_fields():if request.args.get("actionFields") and request.args["actionFields"]["invalid"] == True:return render_template_string(jsonify(errors = [{status= "SKIP", message = "400"}]), 400
Can anyone help me? Thank you very much.