Thursday, 21 July 2022

Python3 django csrf trusted and disable csrf

 make site csrf trusted : 


https://stackoverflow.com/questions/70285834/forbidden-403-csrf-verification-failed-request-aborted-reason-given-for-fail#:~:text=Origin%20checking%20failed%20%2D%20https%3A%2F%2F,Your%20browser%20is%20accepting%20cookies.

Mar, 2022 Update:

If your django version is "4.x.x":

python -m django --version

// 4.x.x

Then, if the error is as shown below:

Origin checking failed - https://example.com does not match any trusted origins.

Add this code to "settings.py":

CSRF_TRUSTED_ORIGINS = ['https://example.com']

In your case, you got this error:

Origin checking failed - https://praktikum6.jhoncena.repl.co does not match any trusted origins.

So, you need to add this code to your "settings.py":

CSRF_TRUSTED_ORIGINS = ['https://praktikum6.jhoncena.repl.co']



disable django csrf 
1) partially for view 

from django.views.decorators.csrf import csrf_exempt

@csrf_exempt
def my_view(request):
    return HttpResponse('Hello world')

2) disable entirelly
'django.middleware.csrf.CsrfViewMiddleware',

No comments:

Post a Comment