This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Anel Hodzic
Recipients Anel Hodzic
Date 2018-09-30.14:50:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1538319010.84.0.545547206417.issue34853@psf.upfronthosting.co.za>
In-reply-to
Content
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('<option selected="true" disabled>Choose product group</option>');
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($('<option></option>').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
History
Date User Action Args
2018-09-30 14:50:10Anel Hodzicsetrecipients: + Anel Hodzic
2018-09-30 14:50:10Anel Hodzicsetmessageid: <1538319010.84.0.545547206417.issue34853@psf.upfronthosting.co.za>
2018-09-30 14:50:10Anel Hodziclinkissue34853 messages
2018-09-30 14:50:10Anel Hodziccreate