Replies: 12 comments 1 reply
|
Seems like you want this: Django-Cors-Headers |
|
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 |
|
@matthiask totally forget about it, @carltongibson maybe reopen the ticket again and @waqasraz could you provide a minimal project for reproducing that issue? |
|
@Zarathustra2 |
|
any updates for this? |
|
All the http requests still seem to go through the |
|
@waqasraz Yes that's correct. @sidharthramesh Requests which are handled by |
|
This still seems the right answer:
Some ASGI middleware will be needed. This is probably out of scope for channels itself. |
|
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: |
|
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. |
|
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. |
Uh oh!
There was an error while loading. Please reload this page.
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.
All reactions