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 step in the CSS section #1596

Open
juanjoconti opened this issue Oct 16, 2019 · 4 comments
Open

Missing step in the CSS section #1596

juanjoconti opened this issue Oct 16, 2019 · 4 comments

Comments

@juanjoconti
Copy link

juanjoconti commented Oct 16, 2019

Custom css from blog.css won't load if the urls.py file is not updated as

from django.contrib import admin
from django.urls import path, include
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('blog.urls')),
] + staticfiles_urlpatterns()
@das-g
Copy link
Member

das-g commented Oct 19, 2019

If you follow the tutorial exactly, CSS should work fine without adding + staticfiles_urlpatterns() in blog.css. (I've just tried it and it works.)

The reason for this is explained in the Django documentation, chapter Managing static files (e.g. images, JavaScript, CSS), section Serving static files during development:

If you use django.contrib.staticfiles as explained above [that is: if you have that listed in INSTALLED_APPS], runserver will do this [serve the static files] automatically when DEBUG is set to True.

When you follow the tutorial, your project will fulfill both these conditions:

In the Your first Django project! section of the tutorial, we use

django-admin.exe startproject mysite .

This generates mysite/settings.py. As generated, that file already sets DEBUG=True (and we never change that in the tutorial) and it also sets INSTALLED_APPS to a list that includes 'django.contrib.staticfiles' (and we never remove that entry during the tutorial).

@LadySith
Copy link

LadySith commented Feb 26, 2020

I ran into this issue just now because I set DEBUG = False in settings.py when I was going through the tutorial at some point. I wasn't supposed to do this. I changed it back to false and the CSS loaded fine just as @das-g said

@mzhao8
Copy link

mzhao8 commented Jul 9, 2023

was working thru the tutorial but blog.css wasn't working. I followed juanjoconti's step and blog.css finally worked for me.

@thibaudcolas
Copy link
Contributor

Shouldn’t this get closed? Having gone through the tutorial with the intended steps, I can confirm there is no need to + staticfiles_urlpatterns().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants