0

Ok I am new to Python, I am using Django here.

I cannot get my Python to see the CSS file and use it. I have tried hardcoding the path, server restarts, nothing works. I can get it to read a Bootstrap CDN however, I am not sure what is wrong.

My File structure is like so:

-migrations

-static
--music
---images
---style.css (the file that i'm trying to get)

-templates
--music
---index.html (where my link attribute is)

I am trying to load the static CSS file in index.html like so:

{% load staticfiles %}
<link rel="stylesheet" type="text/css" href= "{% static 'music/style.css' %}"/>

Here is the CSS:

body {
   background-color: red;
}

Thanks in advance!

4
  • 1
    try with load static, make sure you static_root var is snipping to the static folder Commented Sep 9, 2017 at 19:28
  • @MauricioCortazar I am not sure what static_root is? but i tried {% load static %} and nothing happened. Commented Sep 9, 2017 at 19:32
  • read more about static docs.djangoproject.com/en/1.11/howto/static-files Commented Sep 9, 2017 at 19:37
  • @MauricioCortazar ok I pointed the root at the static file, however nothing changed. Commented Sep 9, 2017 at 19:45

1 Answer 1

4

Add following code in setting.py file

STATIC_ROOT = os.path.join(BASE_DIR,"deploy_to_server")
STATIC_URL = '/static/'

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

And use in your template

<link rel="stylesheet" type="text/css" href= "{% static 'music/style.css' %}"/>

Create static folder in your project

==> static ==> music ==> style.css
==> manage.py

Hope this helps you

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

1 Comment

This works, also I found that Chrome was caching the Style.css, so even after I got it "working" Chrome wasn't displaying it.

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.