-
Notifications
You must be signed in to change notification settings - Fork 185
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
When building with debug = false css is lost #13
Comments
Thanks; I'll look into it when I have a chance (which might not be until after the holidays. In the meantime, it sounds like https://stackoverflow.com/questions/5836674/why-does-debug-false-setting-make-my-django-static-files-access-fail, which is a little confusing because the docker image is set up to use a production server instead of the Django dev server. Anyway, let me know if the SO thread helps. |
With a lot of help @jfroejk the issue has been resolved. We suggest adding the following at the end of the dockerfile:
|
Thanks again for this. I'm making a note in the sample's readme.md, and will also add a note to the VS Code tutorial pointing to this issue. For the sake of keeping things simple, though, I'm not adding the extra line to the main sample or doc, given that it would take quite a bit of explaining that would otherwise distract from the tutorial's purpose. |
No problem. Just an update: It's not actually that the CSS is lost, it's that the static files are not served at all. At first i thought it was css, but the problem was that i used https://pypi.org/project/django-material/ to provide layout/styles. Django material relies on static files. However CDN's work just fine. So generally: Anything depending on static files will fail when debug = false. I suppose one could check for static files by running "manage.py collectstatic". |
Great, thanks for the clarification! |
For from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns += staticfiles_urlpatterns() If you read the sourcecode # https://github.com/django/django/blob/main/django/contrib/staticfiles/urls.py
def staticfiles_urlpatterns(prefix=None):
"""
Helper function to return a URL pattern for serving static files.
"""
if prefix is None:
prefix = settings.STATIC_URL
return static(prefix, view=serve)
# https://github.com/django/django/blob/main/django/conf/urls/static.py
def static(prefix, view=serve, **kwargs):
"""
Return a URL pattern for serving files in debug mode.
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
"""
if not prefix:
raise ImproperlyConfigured("Empty static prefix not permitted")
elif not settings.DEBUG or urlsplit(prefix).netloc:
# No-op if not in debug mode or a non-local prefix.
return []
return [
re_path(
r"^%s(?P<path>.*)$" % re.escape(prefix.lstrip("/")), view, kwargs=kwargs
),
] It returns empty list in Debug=False. |
@kraigb
Static files don't seem to be served when debug = false.
To replicate in vs code + win 10:
No CSS loading. It seems static files are missing...
I tried pushing to webapp with same result. Am i missing something?
The text was updated successfully, but these errors were encountered: