class ChromeLoginView(View):
def get(self, request):
return JsonResponse({'status': request.user.is_authenticated()})
@method_decorator(csrf_exempt)
def post(self, request):
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
return JsonResponse({'status': True})
return JsonResponse({'status': False})
Mi aspetto che il post venga arrestato da csrf, ma restituisce l'errore 403.@csrf_exempt non funziona sulla classe generica vista basata
Ma se rimuovere tale decoratore e farlo nel URLConf
url(r'^chrome_login/', csrf_exempt(ChromeLoginView.as_view()), name='chrome_login'),
che funzionerà.
Che cosa è successo qui? non doveva funzionare, perché immagino sia quello che fa method_decorator. Sto usando python3.4 e django1.7.1
Qualsiasi consiglio sarebbe fantastico.
Si dovrebbe esaminare le django_braces ... – rnevius
@rnevius grazie mille, non si sa mai questo mixin lib per django prima. – castiel
È fantastico! Tanto più che puoi semplicemente aggiungere [CsrfExemptMixin] (https://django-braces.readthedocs.org/en/v1.4.0/form.html#csrfexemptmixin) alla tua vista per farlo funzionare. È quasi come imbrogliare ... – rnevius