Vue + Django Project-Browser cross-domain error: Access-Control-Allow-Origin

Browser error reporting

Check the front end and check the error information as follows

Access to XMLHttpRequest at ‘ ‘ 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


# CorsMiddleware should be prior to CommonMiddleware


After restarting the project, the browser will no longer report cross-domain errors

Similar Posts: