SHARE
TWEET

Untitled

a guest Jun 17th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'LoginView' object has no attribute 'COOKIES'
  2.      
  3. class LoginView(TemplateView):
  4.     authentication_form=LoginForm
  5.     form_class = LoginForm
  6.     redirect_field_name=REDIRECT_FIELD_NAME
  7.     template_name = 'front/login.html'
  8.     initial = {'key': 'value'}
  9.  
  10.     def get(self, request, *args, **kwargs):
  11.         form = self.form_class(initial=self.initial)
  12.         return render(request, self.template_name, {'form': form})
  13.  
  14.     @method_decorator(sensitive_post_parameters())
  15.     @csrf_protect
  16.     @never_cache
  17.     @api_view(['GET', 'POST'])
  18.     def post(self, request, *args, **kwargs):
  19.         form = self.form_class(request.POST)
  20.         print request.COOKIES('csrftoken')
  21.         print request.POST.get('csrfmiddlewaretoken')
  22.         if form.is_valid():
  23.             #if not is_safe_url(url=redirect_to, host=request.get_host()):
  24.             #   redirect_to = resolve_url(settings.LOGIN_REDIRECT_URL)
  25.             print request.POST.get('email')
  26.             #user = self.get_user(request.POST.get('email'))
  27.             #print user
  28.             #auth = UserDataAuthentication(request, user)
  29.             user = authenticate(email=request.POST.get('email'), password=request.POST.get('password'))
  30.             if user is not None:
  31.                 auth_login(request, user)
  32.                 return Response(user, status=status.HTTP_201_CREATED)
  33.         return HttpResponseRedirect('/login/')
  34.      
  35. var csrftoken = $('meta[name="csrf-token"]').attr('content');
  36. SigninView = Backbone.View.extend({
  37.     events: {
  38.         //"click button[type=submit]": "sendRequest"
  39.     },
  40.     sendRequest: function( event ){
  41.         //event.preventDefault();
  42.         var csrftoken = $.cookie('csrftoken');
  43.         var url = '/login/validate/';
  44.         var email = $("#id_email").val();
  45.         var password = $("#id_password").val();
  46.         var items = {
  47.                         email: email,
  48.                         password: password,
  49.                         csrfmiddlewaretoken: csrftoken
  50.                     };      
  51.         console.log(csrftoken);
  52.         $.ajax({
  53.             url:url,
  54.             type:'POST',
  55.             dataType:"json",
  56.             data: items,
  57.             success: function (data) {  
  58.                 var json = $.parseJSON(data);
  59.                 console.log(data);
  60.             },
  61.             error: function (xhr, textStatus, error) {
  62.                 $("#form_error").css('padding','7px').css('border-radius','4px').html('Error recieved: ' + error).fadeIn();
  63.                 console.log("Status: "+textStatus);
  64.                 console.log("Type: "+error);
  65.             }
  66.         });
  67.     }
  68. });
  69. var signin_view = new SigninView({
  70.     el: $("#login_form")
  71. });
  72.      
  73. Traceback:
  74. File "/home/ryuu/Programming/Python/tabr/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  75.   114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
  76. File "/home/ryuu/Programming/Python/tabr/venv/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
  77.   69.             return self.dispatch(request, *args, **kwargs)
  78. File "/home/ryuu/Programming/Python/tabr/venv/local/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
  79.   87.         return handler(request, *args, **kwargs)
  80. File "/home/ryuu/Programming/Python/tabr/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
  81.   29.             return bound_func(*args, **kwargs)
  82. File "/home/ryuu/Programming/Python/tabr/venv/local/lib/python2.7/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
  83.   75.             return view(request, *args, **kwargs)
  84. File "/home/ryuu/Programming/Python/tabr/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
  85.   25.                 return func(self, *args2, **kwargs2)
  86. File "/home/ryuu/Programming/Python/tabr/venv/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  87.   95.                     result = middleware.process_view(request, view_func, args, kwargs)
  88. File "/home/ryuu/Programming/Python/tabr/venv/local/lib/python2.7/site-packages/django/middleware/csrf.py" in process_view
  89.   111.                 request.COOKIES[settings.CSRF_COOKIE_NAME])
  90.  
  91. Exception Type: AttributeError at /login/validate/
  92. Exception Value: 'LoginView' object has no attribute 'COOKIES'
  93.      
  94. from django.utils.decorators import method_decorator
  95.  
  96. csrf_protect_method = method_decorator(csrf_protect)
  97. # and so on
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top