3

I have a style.css file which is common across all the apps in my Django project. It is located as follows:

testsite______
              |
              |
           testsite
              |
              |
             news 
              |
              |
            reviews
              |
              |
           templates------>static------>css------> style.css
              |
              |
           manage.py

In settings.py of the project, I have STATICFILES_DIRS as follows:

STATIC_URL = '/static/'
STATICFILES_DIRS = (
        "/path/to/my/project/templates/static/",
)

I call the css files in the header of my template as follows:

<html>
    <head>
        <title>TEst site</title>
        <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/style.css"/>
    </head>

However, the css doesn't load. It gives a 404 error wherein the server looks for the css file inside the app (news, reviews). The error is as follows:

"GET /test-site/css/style.css HTTP/1.1" 404 4147

Do I need to specify something for css in the urls.py? What am I missing out here?

2
  • 1
    do you have django.contrib.staticfile in INSTALLED_APPS ? more here Commented Sep 4, 2013 at 16:26
  • @karthikr - yes, django.contrib.staticfile is in INSTALLED_APPS Commented Sep 6, 2013 at 5:18

1 Answer 1

4

No, you dont have to specify anything of the css in the urls. Try to put into the HTML

{% load staticfiles %}

and to call a

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

I do it like that and it works fine.

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

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.