DjangoGirls / tutorial

This is a tutorial we are using for Django Girls workshops
http://tutorial.djangogirls.org/
Other
1.53k stars 1.86k forks source link

Missing step in the CSS section #1596

Open juanjoconti opened 5 years ago

juanjoconti commented 5 years ago

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 commented 5 years ago

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 commented 4 years ago

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 commented 1 year ago

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

thibaudcolas commented 1 year ago

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