I have created a class and method as like below. I need to get current page url. But am getting error while calling get_full_path().
class A(object):
def get_
This code cannot work because has some misconceptions:
request
to get_user
get_user
should be self
which points to A instance.return current_url
in A class
).Your code should look like:
class A(object):
current_url = None
def get_user(self, request):
self.current_url = request.get_full_path()
b = A()
b.get_user(request)
print b.current_url
Or if you want to pass full path to constructor of class A
, and for whatever reason use it in inherited class B:
class A(object):
def __init__(self, current_url):
self.url = current_url
def get_path(self):
return self.current_url
class B(A):
# whatever you need here
pass
b = B(request.get_full_path())
print b.get_path() # prints current path