Dica 50 - DRF: Django CORS headers

Github: https://github.com/rg3915/drf-example

https://pt.wikipedia.org/wiki/Cross-origin_resource_sharing

https://github.com/adamchainz/django-cors-headers

python -m pip install django-cors-headers
pip freeze | grep django-cors-headers >> requirements.txt

Edite settings.py

CORS_ALLOWED_ORIGINS = [
    'http://localhost:8080',
]

INSTALLED_APPS = [
    ...,
    'corsheaders',
    ...,
]

MIDDLEWARE = [
    ...,
    # corsheaders
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.common.CommonMiddleware',
    ...,
]

Frontend

Edite router/index.js

touch src/views/Login.vue

Last updated

Was this helpful?