mdn / django-locallibrary-tutorial

Local Library website written in Django; example for the MDN server-side development Django module: https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to enable CORS headers in locallibrary tutorial ?

tbiat opened this issue · comments

Hello,
Thanks for providing this tutorial, helping a lot. I'm trying to enable CORS headers (I followed the https://www.stackhawk.com/blog/django-cors-guide/ ) mainly changing the settings.py file :
INSTALLED_APPS = [
...
'corsheaders',
...
]
MIDDLEWARE = [
...,
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
...,
]
CORS_ALLOW_ALL_ORIGINS = True

But the response still doesn't include CORS. It seems that whatever I do regarding corsheaders in settings.py, it is overridden by something else .

Thanks in advance for the response !

Did you install corsHeaders if not do run this command in your app

pip install django-cors-headers
this enables the cors in your django app

Did you install corsHeaders if not do run this command in your app

pip install django-cors-headers
this enables the cors in your django app

Yes I did. Changing of the config for other middlewares works (referrer policy for instance with the security middleware package), but CORS config looks like not taken into account.

This is a bit out of scope for the tutorial. Closing.

This is a bit out of scope for the tutorial. Closing.

Sorry, I see you are confused. Basically the tutorial covers a number of things, but cross origin sharing is not one of them. This area is for bugs around the tutorial not for support on doing something not covered by the tutorial.