Browser error reporting
Check the front end and check the error information as follows
Access to XMLHttpRequest at ‘ http://127.0.0.1:8000/categorys/ ‘ from origin ‘ http://localhost:8080 ‘ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
Solve cross domain problems through the back end
Refer to the solution on GitHub
Search Django CORS headers to see
1. Installing in a virtual environment
python -m pip install django-cors-headers
2. Configure settings
INSTALLED_APPS = [ ..., "corsheaders", ..., ] MIDDLEWARE = [ ..., "corsheaders.middleware.CorsMiddleware", "django.middleware.common.CommonMiddleware", ..., ] # CorsMiddleware should be prior to CommonMiddleware CORS_ALLOW_ALL_ORIGINS=True
After restarting the project, the browser will no longer report cross-domain errors
Similar Posts:
- ERRORS: ?: (corsheaders.E013) Origin ‘*’ in CORS_ORIGIN_WHITELIST is missing scheme or ne…
- Django @csrf_exempt Cannot work in class view (Django @csrf_exempt not working in class View)
- Django admin Error: ‘WSGIRequest’ object has no attribute ‘user’
- Requested setting INSTALLED_APPS, but settings are not configured. …..DJANGO_SETTINGS_MODULE…..
- ImportError: Couldn’t import Django [How to Solve]
- [Solved] Django cannot create an app after creating a project
- [Django CSRF tutorial] solve the problem of forbidden (403) CSRF verification failed. Request aborted
- Solutions to xadmin’s “apps are’t loaded yet” error
- Django exception-ImportError: No module named django.core.management
- Python2.7 Error: command not found: django-admin.py [How to Solve]