Problem Permissions, Postman working and implemented with VUEJS not working

95 views
Skip to first unread message

Angel Rojas

unread,
Mar 14, 2018, 8:37:13 AM3/14/18
to Django REST framework
hello friends,

I have a problem with django rest framework permissions, well when I run my code with postman woking well, but when implemented using VUEJS with a library axios, return me error 500 and error 403,

well in my application django rest framework I use django-cors, this is my code setting.py 

# django CORS PACKAGE
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = False
CORS_ORIGIN_WHITELIST = ()
CORS_ORIGIN_REGEX_WHITELIST = (r'^(https?://)?(\w+\.)?google\.com$', )

CORS_ALLOW_METHODS = (
'GET',
'POST',
'PUT',
'PATCH',
'DELETE',
'OPTIONS'
)

CORS_ALLOW_HEADERS = (
'accept',
'accept-encoding',
'authorization',
'content-type',
'dnt',
'origin',
'user-agent',
'x-csrftoken',
'x-requested-with',
)

# CSRF_COOKIE_NAME = "csrftoken"

with this configuration return me error 500, and this configuration 
# django CORS PACKAGE
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_WHITELIST = (
'http://locahost:8080'
)
CORS_ORIGIN_REGEX_WHITELIST = (r'^(https?://)?(\w+\.)?google\.com$', )

CORS_ALLOW_METHODS = (
'GET',
'POST',
'PUT',
'PATCH',
'DELETE',
'OPTIONS'
)

CORS_ALLOW_HEADERS = (
'accept',
'accept-encoding',
'authorization',
'content-type',
'dnt',
'origin',
'user-agent',
'x-csrftoken',
'x-requested-with',
)

CSRF_COOKIE_NAME = "csrftoken"

return me error 403,

well my code view.py for this endpoint 

class RegisterPin(generics.UpdateAPIView):
"""
Register PIN the fist time
"""
serializer_class = ProfileSerializer
queryset = Profile.objects.all()
permission_classes = permissions.IsAuthenticated

def put(self, request, pk, *args, **kwargs):
        # do samething
        pass


and this is my code VUEJS for this endpoint

        // lib for connections url API
            import axios from 'axios';
            import Decode from 'jwt-decode';
             import Cookies from 'js-cookie';

            var url_register_pin_local = 'http://127.0.0.1:8000/api/v1/profile/pin-reg/';

           sendOrderBuy: function(){
                
                /*axios.defaults.withCredentials = true;
                axios.defaults.xsrfCookieName = 'csrftoken';                
                axios.defaults.xsrfHeaderName = 'x-csrftoken';*/


                //const servicecookie = this.getCookie('csrftoken');
                //'X-CSRF-Token': servicecookie,

                var pin = this.sendData.pin;
                var decoded = Decode(GetLogin());
                var configHeader = {
                    headers: {
                        'Content-Type': 'application/json', 
                        'Authorization': 'Bearer ' + GetLogin(),
                    }
                }
                console.log('MY COOKIE ;)');
                console.log(Cookies.get('csrftoken'));

                axios.put(url_register_pin_local+decoded.user_id, configHeader)
                  .then(response => {

                    console.log('here PIN');
                    
                  })
                  .catch(function (error) {
                    console.log(decoded);
                    console.log('error PIN');
                    console.log(error);
                    //return error;
                  });
            }


I use gunicorn in so linux debian 9,  will be there a problem server I mean refer gunicorn, please tell me what can I do.

regards 
Angel Rojas

Reply all
Reply to author
Forward
0 new messages