python - Pass parameters to a decorator for a class method is to be decorated -


I am trying to define a decorator in the flask which eventually passed the class methods to pass the parameters of that class installation Will do Here's an example that I really want to do. Rick user_mermission (myname): def decorator (f): @wraps (f) def decorate (* args, **)

And my manager category is defined: if my name == 'my name': return F (* args, argzz) ** Other: return "not allowed" returning decoration

  class manager (flask.views.MethodView): def __init __ (auto, name): self.name = name @user_permission (self.my_name) def post (self): return "response" def (self): return "Response"   

What I'm trying to do Yes, "self" passes class variables from the decorator. Yes "self" is not defined at that point but "@ decorator.asser_promotion (" self.my_name ) "is what I'm actually trying because My problem has not been resolved yet.

I could not find a solution. Does anyone know about these things?

As you say, self is not defined at that point it can never work , As is done in the form of decorator when class is defined, whereas for example it is said when you want to run something.

Although I think that you really are more dependent on this. The method itself is passed by itself so there is no reason to try and create a parameter for the decorator, because the decorator has access to method arguments. It would be very simple:

  URF URI Execution from FunkTask Import (): wraps (f) Deaf was decorated (self, * algs, ** quad): if self.myname == 'My name ': Refund F (self, * args, ** kwargs) Other: Back "not allowed" return decorated    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -