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

Figure out how to make `runserver_nostatic` work with Channels #77

Closed
evansd opened this issue Mar 22, 2016 · 9 comments

Comments

Projects
None yet
7 participants
@evansd
Copy link
Owner

commented Mar 22, 2016

At present, runserver_nostatic works by simply shadowing the runserver command from contrib.staticfiles and replacing it with the runserver command from Django core. However, this won't work with Channels, which needs its own runserver command.

A possible approach might be to require that runserver_nostatic be at the top of the INSTALLED_APPS list and for it to discover the next highest priority runserver command (by inspecting the app registry and delegate to that, after setting the appropriate --no-static flag.

This is obviously more complex and fragile, but it would be nice to have a simple (for the user) solution which was agnostic as to whether Channels was being used.

@amureki

This comment has been minimized.

Copy link

commented Jun 13, 2016

@evansd

maybe not very related, but I wonder if whitenoise is working with current channels approach?
for example,

from channels.asgi import get_channel_layer
from whitenoise import WhiteNoise

channel_layer = get_channel_layer()
channel_layer = WhiteNoise(channel_layer)

would not work, of course, but is there any way to make it work?

@evansd

This comment has been minimized.

Copy link
Owner Author

commented Jun 13, 2016

@amureki

Yes, you can now integrate WhiteNoise by adding it to settings.MIDDLEWARE_CLASSES rather than editing wsgi.py. This works with standard Django and with Channels.

See:
http://whitenoise.evans.io/en/stable/changelog.html#simpler-cleaner-django-middleware-integration

@edevil

This comment has been minimized.

Copy link

commented Jan 31, 2017

So can this be closed?

@evansd

This comment has been minimized.

Copy link
Owner Author

commented Feb 1, 2017

@edevil No, I don't think so. WhiteNoise works fine with Channels, but the small "runserver_nostatic" feature doesn't. You can either ignore the issue in which case your app will use the default static file handling when in DEBUG mode, or you can manually pass the --nostatic option to runserver.

@sajoku

This comment has been minimized.

Copy link

commented Jun 19, 2017

I also ran into this and had channels defined after 'whitenoise.runserver_nostatic',. This will run the server runserver fine but does not initiate the channels part. Very confusing (also because I'm new to Django and Python probably). So it seems there's nothing wrong with the configuration but the channels part will not be loaded at all. Even doing

CHANNEL_LAYERS = {
        "default": {
            "BACKEND": "asgiref.inmemory.ChannelLayer",
            "ROUTING": "uadoua.routing.channel_routing",
            },
        }

Where uadoua.routing.channel_routing is non existent will not fail and just run the server.

I'm running versions:

whitenoise==3.3.0
Django==1.11.1

From above discussion I would think this will fail in the proposed solution right?

@decentral1se

This comment has been minimized.

Copy link

commented Jun 26, 2017

FYI, I got bitten by this one pretty badly over at django/channels#684.

We probably should come up with a fix here. At the very least, a runtime warning.

@edmorley

This comment has been minimized.

Copy link
Contributor

commented Jun 26, 2017

I wonder if a better solution is to upstream a fix to Django that adds a way to disable the contrib.staticfiles via configuration pref or similar? WhiteNoise's runserver_nostatic would then no longer be required at all.

@evansd

This comment has been minimized.

Copy link
Owner Author

commented Jul 4, 2017

Fixed in ce74438, which will form part of the upcoming 4.0 release.

@evansd evansd closed this Jul 4, 2017

@SHxKM

This comment has been minimized.

Copy link

commented Jul 9, 2018

@evansd Can I use 4.0 right now? My site is extremely slow with Channels 2 & WhiteNoise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.