How to capture parameters sent by the GET method?

2

This is the way I use but I do not get to capture the parameter in the controller enters the else but does not capture:

def get(self, request, *args, **kwargs):

        if request.method=='POST':
            print "rrr" * 99
        else:
            a=request.GET['user']
            print('aa'*20)
            print a
    
asked by Eric 19.05.2016 в 01:04
source

3 answers

1

Try this way:

a = request.GET.get('user')
    
answered by 19.05.2016 / 01:32
source
0

The correct way to obtain the variable using Django is correct,

a = request.GET['user']
print a

It seems to me that the parameter is not really called "user".

    
answered by 19.05.2016 в 01:27
0

If what you are trying to do is get the user that is logged in, this is always available in request , to get it you just have to do this:

def get(self, request, *args, **kwargs):
    user = request.user
    # ...
    
answered by 19.05.2016 в 14:05