Why do you use a third component to have a rest api? instead of the django rest framework?
Since the problem is inside your custom falcon server, its not in any way related to django .. ask the falcon comunity here instead: https://gitter.im/falconry/user
Am Mittwoch, 2. November 2016 14:29:25 UTC+1 schrieb Oguz Yarimtepe:
-- Since the problem is inside your custom falcon server, its not in any way related to django .. ask the falcon comunity here instead: https://gitter.im/falconry/user
Am Mittwoch, 2. November 2016 14:29:25 UTC+1 schrieb Oguz Yarimtepe:
I have a django app and at the template part i have javascript function calling the rest api:
<!-- Custom Theme JavaScript --><script src="/static/js/ select-autofiller.js "></script> At the js file i am filling a select box according to the returned json response$('#field1').change(function(){
var var1=$("#filed2").val();
var var2=$("#field1 option:selected").text();
url="http://www.foo.com:8080/" + var1 + "/" + var2 + "/";
$.get(url, function( data ) {
alert( "Load was performed." + data);
});
});The Django web app is running on www.foo.com:8000At the rest api side, falcon is running and i installed falcon-corsimport falcon
from wsgiref import simple_serverfrom falcon_cors import CORS
check_python()
cors = CORS(allow_origins_list=settings.ALLOWED_ORIGINS)
api = falcon.API(
media_type='application/json',
middleware=[
# json.RequireJSON(),
# json.JSONTranslator(),
https.RequireHTTPS(),
headers.BaseHeaders(),
handle_404.WrongURL(),
cors.middleware
],
)***route definitions****httpd = simple_server.make_server('0.0.0.0' , 8080, api)
httpd.serve_forever()ALLOWED_ORIGINS is a list: ['www.foo.com:8000', 'www.foo.com:8080']Still when i select the box and triggered the js at the Django web app, i am gettingXMLHttpRequest cannot load http://www.foo.com:8080/var1/var2 . Response to preflight request doesn't pass access control check:No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.foo.com:8000' is therefore not allowed access. The response had HTTP status code 400.I couldn't find ow to fix it.Any idea?
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/aa0910f6-8950-45b7-97ee-91411b97e961%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment