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.

classification
Title: Python django cors
Type: Stage: resolved
Components: Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Anel Hodzic, ammar2
Priority: normal Keywords:

Created on 2018-09-30 14:50 by Anel Hodzic, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg326726 - (view) Author: Anel Hodzic (Anel Hodzic) Date: 2018-09-30 14:50
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
msg326728 - (view) Author: Ammar Askar (ammar2) * (Python committer) Date: 2018-09-30 14:54
Hey Anel, this bug tracker is for issues with the Python language itself, not its libraries or usage.

Try the flask-cors issue tracker or stackoverflow for more help-oriented questions:

https://github.com/corydolphin/flask-cors

https://stackoverflow.com/
History
Date User Action Args
2022-04-11 14:59:06adminsetgithub: 79034
2018-09-30 14:54:02ammar2setstatus: open -> closed

nosy: + ammar2
messages: + msg326728

resolution: not a bug
stage: resolved
2018-09-30 14:50:10Anel Hodziccreate