Issue
I come from PHP/Laravel Background where for calling methods or accessing properties within a class ,use of $this keyword is sufficient.In python3/Django4.0.6 i have to use request as first parameter to capture the request body for eg.
class CustomAuth:
def verifyToken(token):
pass
def login(request):
data = request.body
# how do i call verifyToken?
# if i use self as first argument then i am not able to access the request
Solution
This would be relatively standard based on what you are asking:
class CustomAuth:
def verifyToken(self, token):
self.token = token
def login(self, request):
self.request = request
data = request.body
# how do i call verifyToken?
x = self.verifyToken(self.token)
# if i use self as first argument then i am not able to access the request
r = self.request
Also, note the comments suggesting the @staticmethod
method as an alternative.
Answered By - D.L
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.