Skip to content

Figure out how to make runserver_nostatic work with Channels #77

Closed
@evansd

Description

@evansd
Owner

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.

Activity

amureki

amureki commented on Jun 13, 2016

@amureki

@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

evansd commented on Jun 13, 2016

@evansd
OwnerAuthor

@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

edevil commented on Jan 31, 2017

@edevil

So can this be closed?

evansd

evansd commented on Feb 1, 2017

@evansd
OwnerAuthor

@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

sajoku commented on Jun 19, 2017

@sajoku

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

decentral1se commented on Jun 26, 2017

@decentral1se

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

edmorley commented on Jun 26, 2017

@edmorley
Contributor

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

evansd commented on Jul 4, 2017

@evansd
OwnerAuthor

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

SHxKM

SHxKM commented on Jul 9, 2018

@SHxKM

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

timkofu

timkofu commented on Mar 30, 2022

@timkofu

Is this still an issue with Django 4x, Channels 3x and Whitenoise 6x?

adamchainz

adamchainz commented on Mar 30, 2022

@adamchainz
Collaborator

There was a commit to fix this. Did you try? Please also don't comment on 5 year old issues, only open a new one if you have information.

Repository owner locked as resolved and limited conversation to collaborators on Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @edevil@evansd@sajoku@edmorley@timkofu

        Issue actions

          Figure out how to make `runserver_nostatic` work with Channels · Issue #77 · evansd/whitenoise