3

Hi there I'm extremely new to programming/python/django in general and I'm following the django for beginners book and the part where we add in CSS has got me super confused because I'm getting this error "GET /static/css/base.css HTTP/1.1" 404 1660. I've copied the code from the book 1 to 1 and can't get it to work.

Here's the relevant settings.py

STATIC_URL = '/static/'

STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]

Here's the base.html I'm adding the css to

{% load static %}
<html>
    <head>
        <title>Django blog</title>
        <link href="{% static 'css/base.css' %}" rel="stylesheet">
    </head>

...

And here's the directory info I saw people asking about this in other questions

C:.
├───blog
│   └───migrations
├───blog_project
├───static
│   └───css
└───templates
3
  • 1
    Do you have a base.css file in the directory? Commented Jan 10, 2020 at 20:11
  • Yes there's a base.css file in the directory. And what do you mean by strongly typed language? I've really taken a liking to python and I think I just want to power through and learn it. Commented Jan 11, 2020 at 0:14
  • Okay nevermind I'm stupid and was updating settings for a different project... lmao Commented Jan 11, 2020 at 0:36

6 Answers 6

3

Try this:

Move the static folder from the project root into the particular App directory. Do that for all the apps you create as Django uses django.contrib.staticfiles which takes care of all static files in your project. As referenced here

Sign up to request clarification or add additional context in comments.

Comments

2

make sure you have the file base.css in the css folder then for some weird reasons try using double-quotes.

STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]

Comments

2

In Django, there is one root static directory which lives under the project directory (at the same level of apps directories),in addition to this, there are other static directories live under Apps directories, and for each app which needs to use static files, A static directory should be created under it to host its particular static staff, so make sure to create static directory under each app so its views and templates can access them and run collectstatic whenever new static staff is added to static directories.

make sure in Setting file that STATIC_DIRC = [ "BASE-DIR /[App-Name].static"] for each app has static directory, dont include the root static directory otherwise Django will throws an error

I have faced this issue and spent few hours looking for solution which I finally got and the credit goes to Asiak answer (mentioned above)

Comments

0

I had the same issue for a while. As you have explained, your code is alright and files are placed in the right directories. However, what I found out to be my issue was not including the following in the app/urls.py

from django.conf import settings
from django.conf.urls.static import static

 urlpatterns = [
     # ... the rest of your URLconf goes here ...
 ]+ static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)

For a better explanation check out the documentation django-staticfiles documentation

Comments

0

close The Sever And Run it again

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
0

"GET /static/css/base.css HTTP/1.1" 404 1660

First of all check out if base.css is placed in css directory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.