Replies: 12 comments 1 reply
-
Seems like you want this: Django-Cors-Headers |
Beta Was this translation helpful? Give feedback.
-
Thanks @Zarathustra2, yes. |
Beta Was this translation helpful? Give feedback.
-
I don't think django-cors-headers will work since, at least in my understanding, Django's middleware does not run when you're using @waqasraz Maybe you have some luck using ASGI middleware from the Starlette project, e.g. https://www.starlette.io/middleware/#cors-preflight-requests |
Beta Was this translation helpful? Give feedback.
-
@matthiask totally forget about it, @carltongibson maybe reopen the ticket again and @waqasraz could you provide a minimal project for reproducing that issue? |
Beta Was this translation helpful? Give feedback.
-
@Zarathustra2 |
Beta Was this translation helpful? Give feedback.
-
any updates for this? |
Beta Was this translation helpful? Give feedback.
-
All the http requests still seem to go through the |
Beta Was this translation helpful? Give feedback.
-
@waqasraz Yes that's correct. @sidharthramesh Requests which are handled by |
Beta Was this translation helpful? Give feedback.
-
This still seems the right answer:
Some ASGI middleware will be needed. This is probably out of scope for channels itself. |
Beta Was this translation helpful? Give feedback.
-
Hi all, do you know how to mount the CORSMiddleware component from Starlette onto a Django Channels app? At the Starlette documentation linked above (https://www.starlette.io/middleware/#cors-preflight-requests) there is a section at the bottom "Using middleware in other frameworks" where I tried to follow their suggestion, but I'm still getting a CORS error from my React app. Here is my routing.py file:
I have also tried the same in my asgi.py file, still getting CORS error:
|
Beta Was this translation helpful? Give feedback.
-
Ah whoops, just took a fresh look at this and realized I was missing the CORSMiddleware component from my wsgi.py as well (implemented about the same as how the asgi.py file looks). Everything is working now and getting no CORS error! Going to leave my previous comment up in case someone else runs into the same problem. |
Beta Was this translation helpful? Give feedback.
-
I'm going to convert this to a discussion, since I don't think it's an Issue per se. Happy to link to a blog post or package wrapping up what's needed here. |
Beta Was this translation helpful? Give feedback.
-
Access to XMLHttpRequest at 'http://127.0.0.1:8001/test_middleware/' from origin 'http://127.0.0.1:8082' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Adding a header to each send response solve the above problem but I don't want to add a header to each response.
Beta Was this translation helpful? Give feedback.
All reactions