B
B
bigtrouble2016-01-14 18:27:01
Python
bigtrouble, 2016-01-14 18:27:01

How to see the class to which the method belongs?

In general, I want to figure out how janga works when it calls CBV, what classes it refers to, what it requests and I want to display the "class -> method / attribute" list, I
try to do this

def __getattribute__(self, *args, **kwargs):
        (string,) = args
        if ('__class__' != string):
            print(self.__class__.__name__, ' ', *args)
        return super().__getattribute__(*args, **kwargs)

It outputs only the name of the parent, how can you see which class which method belongs to?
UPD2: Who cares here is the solution
def __getattribute__(self, *args, **kwargs):
        (string,) = args
        if '__class__' != string:
            from inspect import isfunction
            if hasattr(self.__class__, string):
                if isfunction(getattr(self.__class__, string)):
                    print(getattr(self.__class__, string).__qualname__, ' ', *args, **kwargs)
        return super().__getattribute__(*args, **kwargs)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nerevar_soul, 2016-01-14
@Nerevar_soul

When I dealt with CBV, I used this site . There is very clearly all the links and code can be traced.

U
un1t, 2016-01-14
@un1t

Is it not fate to look at the source codes?
https://github.com/django/django/tree/master/djang...
In views, everything is as simple as two fingers.

A
abcd0x00, 2016-01-15
@abcd0x00

Output self.__class__ .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question