CSRF verification failed. Request aborted.

Sangeeth Sajan 21 Reputation points
2022-12-14T14:26:08.257+00:00

270615-image.png

I'm getting this error. I tried giving CSRF_TRUSTED_ORIGINS = ['https://site.azurewebsites.net/'], CORS_ALLOWED_ORIGINS = ['https://site.azurewebsites.net/']. But landed on the same issue while submitting the form. ALLOWED_HOSTS =[os.environ['WEBSITE_HOSTNAME']] if 'WEBSITE_HOSTNAME' in os.environ else []
My middleware have
"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware" and 'django.middleware.csrf.CsrfViewMiddleware'

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,781 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sangeeth Sajan 21 Reputation points
    2022-12-15T14:24:30.553+00:00

    Hi,
    I found the answer.

    To get the csrf_token working properly we need to add
    CSRF_TRUSTED_ORIGINS = ['https://'+ os.environ['WEBSITE_HOSTNAME']]

    Hope this might be helpful to others

    2 people found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.