Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serving static files on Django (Channels) #193

Closed
ebsaral opened this issue Sep 20, 2018 · 4 comments
Closed

Serving static files on Django (Channels) #193

ebsaral opened this issue Sep 20, 2018 · 4 comments

Comments

@ebsaral
Copy link

ebsaral commented Sep 20, 2018

Hey there. I am trying to replace Daphne with Uvicorn. Daphne was allowing to serve static files even though it wasn't ideal.

Now I replaced it, and it works fine right now on staging server, but I am not able to serve static files through Gunicorn with Uvicorn worker. I am on Heroku, so nginx is not an option. I know it would be easier though.

I am using the latest version of everything. Is there any undocumented hack around this?

I wanted to serve the static files over S3 with django_storage but there are hardcoded static urls in css and js files. This creates complexity.

Thanks.

@ebsaral ebsaral changed the title Serving static files on Django Serving static files on Django (Channels) Sep 20, 2018
@tomchristie
Copy link
Member

Daphne was allowing to serve static files even though it wasn't ideal.

I'm not quite sure what you mean - daphne itself doesn't have any configuration for serving static files. eg. see django/channels#87

(Although running Django Channels does support it, and you can use either uvicorn or daphne as the server for running channels. Are you using Channels or some other ASGI framework?)

@ebsaral
Copy link
Author

ebsaral commented Sep 20, 2018

@tomchristie excuse my terrible explanation please. I am just new to all this ASGI logic.

I am running Django Channels 2 right now. I was using Django Channels 1.x with Daphne as explained in documentation, and the server was serving static files by adding route('http.request', StaticFilesConsumer()) in the channel routing. I am looking for something similar.

Django Channels 2 should do this automatically in the routing file?
I see it adds http->django by default but I can't access static files.

The command I am running:
gunicorn MyApp.asgi:channel_layer -b 0.0.0.0:$PORT -w 2 -k uvicorn.workers.UvicornWorker

Should I expect Django Channels to serve stating files after running this?

@ebsaral
Copy link
Author

ebsaral commented Sep 20, 2018

Or does this require configuration on Django Channels side which is not really related to Uvicorn?

@tomchristie
Copy link
Member

Or does this require configuration on Django Channels side which is not really related to Uvicorn?

Exactly, yup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants