0

Here's the code I have:

In the HTML file:

<link rel="stylesheet" href={% static 'css.css' %}" >

In settings.py:

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

The css.css file is located in the static directory which is in the same directory as manage.py , So why isn't the css file loading?

There is also a js file which doesn't seem to be loading either, and it's in the same directory as the CSS file and I'm loading it in with the same method as the CSS file.

Also, my pc isn't currently connected to WiFi, in case it makes a difference. I'm working with localhost.

2
  • dont forget to add this to the template {% load static %} Commented Nov 18, 2017 at 13:35
  • try changing the staticfilesDir bracket from () to [ ] Commented Nov 18, 2017 at 13:42

1 Answer 1

1

Have you configured your Static files URL. According to best practice

STATIC_URL = '/static/'

Actually the above is too little information to help anyway. Can you tell us the application environment (production/development) etc because there are specific configurations for each in Django. Also please provide code using the code markup. Assuming you are using Django 1.11, read this for a better understanding or better yet see a tutorial for beginners

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

4 Comments

I am using code markup but it isn't working maybe it's because I'm on mobile, and what do you mean by application environment? I'm using a virtual environment , unless that's not what you mean
And yes, I have configured STATIC_URL
Hussam no, he is asking if you are running the server on your local machine or it's production server(worldwide)
Mohammed , exactly. Also, I saw your comment above to convert the STATICFILES_DIRS to a list from a tuple, but in practice doesn't really matter. :D <br> On a serious note, maybe share the releavnt code samples from both settings.py and the template being referred to above.

Your Answer

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