Enable the CachedStaticFilesStorage in your settings and turn DEBUG off.
{{{
DEBUG = False
STATICFILES_STORAGE =
'django.contrib.staticfiles.storage.CachedStaticFilesStorage'
}}}
Turn on the runserver with the insecure flag
{{{ $ python manage.py runserver --insecure }}}
Visit your runserver in your browser, and the static files will not load.
When using the default
django.contrib.staticfiles.storage.StaticFilesStorage the static files
will load.
The reason is because of this section in contrib/staticfiles.storage.py
{{{
100 def url(self, name, force=false):
101 """
102 Returns the real URL in DEBUG mode.
103 """
104 if settings.DEBUG and not force:
105 hashed_name, fragment = name, ''
106 else:
}}}
When DEBUG is False, the automatic static file serving in runserver is
disabled. But using runserver with --insecure will re-enable it. Because
the CachedStaticFilesStorage only looks at the DEBUG flag, it will not
work properly in this scenario. Perhaps that force parameter could be set
to True when the --insecure flag is passed to runserver?
Yes, this is an extremely rare and low-priority edge case, but still a
bug.
It's also not clear what the expected behavior is when both the --nostatic
and --insecure flags are passed to runserver simultaneously. They sort of
cancel each other out. Personally I feel the nostatic should take
priority.
--
Ticket URL: <https://code.djangoproject.com/ticket/19295>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* needs_better_patch: => 0
* resolution: => fixed
* needs_tests: => 0
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/19295#comment:1>
* status: closed => reopened
* resolution: fixed =>
--
Ticket URL: <https://code.djangoproject.com/ticket/19295#comment:2>
* needs_better_patch: => 0
* stage: Unreviewed => Design decision needed
* needs_tests: => 0
* needs_docs: => 0
Comment:
I can reproduce the issue, but I don't know how to fix it.
--
Ticket URL: <https://code.djangoproject.com/ticket/19295#comment:1>
* type: Bug => Cleanup/optimization
* stage: Design decision needed => Accepted
Comment:
I'm pretty sure you're way out of scope for both runserver and the
CachedStaticFilesStorage. So to answer your question, to fix this "bug"
stop using --insecure in the first place.
I'm accepting this ticket to warn users in the docs that both modes are
incompatible.
--
Ticket URL: <https://code.djangoproject.com/ticket/19295#comment:2>
* component: contrib.staticfiles => Documentation
* easy: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/19295#comment:3>
* owner: nobody => kedmiston
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/19295#comment:4>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"028db9750357d504c55a7ac686c9abaa3c847ac6"]:
{{{
#!CommitTicketReference repository=""
revision="028db9750357d504c55a7ac686c9abaa3c847ac6"
Fixed #19295 -- Documented that CachedStaticFilesStorage isn't compatible
with runserver --insecure.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/19295#comment:5>
Comment (by Tim Graham <timograham@…>):
In [changeset:"afc624cab015be3c05dbe2c184416c4838db4b82"]:
{{{
#!CommitTicketReference repository=""
revision="afc624cab015be3c05dbe2c184416c4838db4b82"
[1.5.x] Fixed #19295 -- Documented that CachedStaticFilesStorage isn't
compatible with runserver --insecure.
Backport of 028db97503 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/19295#comment:6>
Comment (by Tim Graham <timograham@…>):
In [changeset:"2c73ba88f25230e9e62293d25de7526d018041e8"]:
{{{
#!CommitTicketReference repository=""
revision="2c73ba88f25230e9e62293d25de7526d018041e8"
[1.6.x] Fixed #19295 -- Documented that CachedStaticFilesStorage isn't
compatible with runserver --insecure.
Backport of 028db97503 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/19295#comment:7>
Comment (by Tim Graham <timograham@…>):
In [changeset:"4a861e88508eacdb8d0d5bc43f9a0576cedb9f22" 4a861e88]:
{{{
#!CommitTicketReference repository=""
revision="4a861e88508eacdb8d0d5bc43f9a0576cedb9f22"
Refs #19295 -- Doc'd that ManifestStaticFilesStorage doesn't work with
runserver --insecure.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/19295#comment:8>
Comment (by Tim Graham <timograham@…>):
In [changeset:"36b4def91597d522fa73f9b3cb7d0530fe34bc62" 36b4def9]:
{{{
#!CommitTicketReference repository=""
revision="36b4def91597d522fa73f9b3cb7d0530fe34bc62"
[2.0.x] Refs #19295 -- Doc'd that ManifestStaticFilesStorage doesn't work
with runserver --insecure.
Backport of 4a861e88508eacdb8d0d5bc43f9a0576cedb9f22 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/19295#comment:9>