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

Missing support for --nostatic and --insecure options in Daphne's runserver command #449

Closed
davidfb opened this issue Nov 4, 2022 · 4 comments

Comments

@davidfb
Copy link
Contributor

davidfb commented Nov 4, 2022

The django.contrib.staticfiles app includes a custom runserver command that shadows the default runserver command from Django in order to provide a way of easily serving static files, normally in a dev env.

Daphne's own runserver command is supposed to shadow django.contrib.staticfiles' command as well, if present, and provide all the extra bits and pieces in order to support Django Channels. Serving of static files is still done by leveraging django.contrib.staticfiles' ASGIStaticFilesHandler class, so we could say that, in this particular matter, Daphne is working as a kind of wrapper for django.contrib.staticfiles' functionality. And yet, there are two command arguments (--nostatic and --insecure) that can be passed to django.contrib.staticfiles' runserver that cannot be passed to Daphne's because it doesn't recognize them.

Strangely enough, code at Daphne's command seems to be already prepared to take into account such two configuration options (usages of use_static_handler and insecure_serving options at https://github.com/django/daphne/blob/main/daphne/management/commands/runserver.py#L150 to respectively prevent or force the serving of static files if required to do so), but the command arguments to populate those options are missing.

Is it possible that defining these two command arguments in the runserver command's add_arguments() function was somehow forgotten? Or given the similarities in the naming of such options and in the way they're being used, that exactly matches the code at django.contrib.staticfiles' command (https://github.com/django/django/blob/main/django/contrib/staticfiles/management/commands/runserver.py#L32), could it be that there was a plan to make Daphne's command extend the one from django.contrib.staticfiles, that defines those two arguments, but ended up extending Django core's runserver command instead, thus missing the arguments definition?

We need the ability to avoid serving static files through django.contrib.staticfiles in our dev env because we handle that traffic by other means, and this has been proven problematic when using Daphne.

Thank you.

@carltongibson
Copy link
Member

Ok, yes, this would be a reasonable addition.

Would you like to make a PR?

Thanks.

@davidfb
Copy link
Contributor Author

davidfb commented Nov 8, 2022

PR available at #450 waiting for approval.

@davidfb davidfb closed this as completed Nov 8, 2022
@mangelozzi
Copy link

I just pip installed the lastest stable version of channels[daphne]==4.2.0 and runserver still does not recognize --no-static:

DJANGO CHECKS... SKIPPING (enable in example/script/run.sh)

RUN SERVER...
DEBUG PROCESS 462535: 1. Handles Requests, 2. Handles hot reload (of 1)
usage: manage.py runserver [-h] [--ipv6] [--nothreading] [--noreload] [--noasgi]
                           [--http_timeout HTTP_TIMEOUT]
                           [--websocket_handshake_timeout WEBSOCKET_HANDSHAKE_TIMEOUT]
                           [--version] [--settings SETTINGS] [--pythonpath PYTHONPATH]
                           [--no-color] [--force-color] [--skip-checks]
                           [addrport]
manage.py runserver: error: unrecognized arguments: --nostatic

@mangelozzi
Copy link

Okay I see the PR was never merged, maybe we can reopen the issue, because 2 years later it still has not been resolved?

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

3 participants