diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index bba9554af4..875ece2eca 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -44,6 +44,7 @@ Listed in alphabetical order. 18 `@dezoito`_ 2O4 `@2O4`_ a7p `@a7p`_ + Aadith PM `@aadithpm`_ Aaron Eikenberry `@aeikenberry`_ Adam BogdaƂ `@bogdal`_ Adam Dobrawy `@ad-m`_ @@ -235,6 +236,7 @@ Listed in alphabetical order. Yuchen Xie `@mapx`_ ========================== ============================ ============== +.. _@aadithpm: https://github.com/aadithpm .. _@a7p: https://github.com/a7p .. _@2O4: https://github.com/2O4 .. _@ad-m: https://github.com/ad-m diff --git a/{{cookiecutter.project_slug}}/config/settings/base.py b/{{cookiecutter.project_slug}}/config/settings/base.py index 7f339fadca..f69908c2da 100644 --- a/{{cookiecutter.project_slug}}/config/settings/base.py +++ b/{{cookiecutter.project_slug}}/config/settings/base.py @@ -80,6 +80,7 @@ {%- if cookiecutter.use_drf == "y" %} "rest_framework", "rest_framework.authtoken", + "corsheaders", {%- endif %} ] @@ -134,6 +135,9 @@ # https://docs.djangoproject.com/en/dev/ref/settings/#middleware MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", +{%- if cookiecutter.use_drf == 'y' %} + "corsheaders.middleware.CorsMiddleware", +{%- endif %} {%- if cookiecutter.use_whitenoise == 'y' %} "whitenoise.middleware.WhiteNoiseMiddleware", {%- endif %} @@ -321,6 +325,10 @@ ), "DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",), } + +# django-cors-headers - https://github.com/adamchainz/django-cors-headers#setup +CORS_URLS_REGEX = r"^/api/.*$" + {%- endif %} # Your stuff... # ------------------------------------------------------------------------------ diff --git a/{{cookiecutter.project_slug}}/requirements/base.txt b/{{cookiecutter.project_slug}}/requirements/base.txt index ba62bae083..bf61526600 100644 --- a/{{cookiecutter.project_slug}}/requirements/base.txt +++ b/{{cookiecutter.project_slug}}/requirements/base.txt @@ -41,4 +41,6 @@ django-redis==4.12.1 # https://github.com/jazzband/django-redis {%- if cookiecutter.use_drf == "y" %} # Django REST Framework djangorestframework==3.11.0 # https://github.com/encode/django-rest-framework +# Django CORS Headers +django-cors-headers==0.01 # https://github.com/adamchainz/django-cors-headers {%- endif %}