Setting correct STATIC_URL path to get CSS style working in tutorial Pt. 6

I had been following Part 6 of the getting started tutorial and hit a wall at the styling part. The problem appears to have something to do with this setting as described in the docs.

There have been two similar issues mentioned here in the last four years, but neither mentioned the solution I found (and which is mentioned in a Geeksforgeeks article and a Medium post that I’m not able to link to since I’m a new user):

STATIC_URL = '/static/' appears to be the required path to get browsers to find the style.css in development when using manage.py runserver.

However, STATIC_URL = 'static'/ is what appears in my settings.py by default and what is mentioned in the static-files “howto” linked above.

The topic of serving static files appears to fraught with confusion. Is there something I’m not understanding about this situation? Is there an error in the documentation?

This is not a requirement by itself. There are a combination of settings including STATICFILES_DIRS, STATICFILES_FINDERS, your INSTALLED_APPS, and additionally, possibly settings in your urls.py file. They all work together, and changing any one can possibly create the need to change one or more of the others to match.

There are a lot more details about this available at Serving static files during development.

The difference between having STATIC_URL = 'static/' and STATIC_URL = '/static/' is documented in the green note box in the docs for STATIC_URL.

But the bottom line here is that yes - manging static files can be an intricate process, and ensuring they work both in development and production environments does require an understanding of a number of different elements.

Thank you the helpful response and for directing me to the green note box in the documentation for STATIC_URL. I’ll confess to finding the explanation there somewhat opaque!

For someone following the tutorial, my guess is that “the server-provided value of SCRIPT_NAME” is something that is set without our awareness (perhaps when calling django-admin startproject)? Under what circumstances is it not set?

Maybe it’s unnecessary to speculate about this when you’re just “getting started.” Still, it seems disconcerting that the tutorial wouldn’t clarify that there may be a problem–doesn’t this lil’ / affect everyone? Maybe the frustration newcomers must persevere through in order to track down something like that is just toughening us up.

Thanks again.

Actually, it’s more common that SCRIPT_NAME is not set. It’s really only needed when you’re running multiple projects (not necessarily all Django-related) and you want to shift the path at which the project is to be accessed.

There is no current problem in the tutorial. However, the tutorial must be followed precisely and exactly as written.

If someone is experiencing an issue where the tutorial is not working as described, then my initial assumption is always that a mistake has been made somewhere along the line. Over the past 5 years trying to help people here, that assumption has never failed to be the explanation.

Glad to know Django documentation is robust. From the experience of working through all eight parts of tutorial, I understand how the slightest deviation will cause problems.

I do consider myself a thorough and careful reader. In case I ever have to help someone else, I really want to understand went wrong on my end.

Where is the information in part 6 that, if read and followed precisely, would’ve prevented me from having to add a forward slash in my settings.py in order to get the styling picked up? The only thing I can see is that the yellow warning box mentions STATIC_URL, but doesn’t instruct the reader to change anything at this point.

It’s possible I made a mistake in another part of the tutorial, but either way, I appreciate your help in tracking it down.

I can’t really determine that without seeing your settings, urls, and template
files.

The tutorial does work, regardless of whether you add the leading '/', assuming standard configurations throughout the rest of the project for those elements relating to static files. (I just reconfirmed this with my own copy of the polls tutorial.)

Thank you–it’s going to drive me crazy but I’ll move on. Hope this helps someone else who just wants to see their damn links turn green and don’t why they’re not!