Issue 34853: Python django cors (original) (raw)
API call gives the desired response when trying through browser or postman.
from rest_framework import generics from django.shortcuts import get_object_or_404 from .jsonserializer import GroupSerializer, SubgroupSerializer, ProductsSerializer from .models import pGroups, pSubgroups, Products from flask import Flask from flask_cors import CORS
app = Flask(name) CORS(app)
@app.route("/Group/")
@cross_origin()
Create your views here.
class GroupList(generics.ListCreateAPIView): queryset = pGroups.objects.all() serializer_class = GroupSerializer
But when i try to make that call using JQuery
let dropdown = $('#locality-dropdown');
dropdown.empty();
dropdown.append(''); dropdown.prop('selectedIndex', 0);
const url = 'http://127.0.0.1:8000/Group/';
// Populate dropdown with list of provinces $.getJSON(url, function (data) { $.each(data, function (key, entry) { console.log(entry.name); dropdown.append($('').attr('value', entry.abbreviation).text(entry.name)); }) });
I get the output :
Failed to load http://127.0.0.1:8000/Group/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
Trying to set up the FLASK-CORS https://flask-cors.readthedocs.io/en/latest/
Im complete beginner in web programming