user1431282
user1431282

Reputation: 6835

Serving Static Files [Beginner]

I've been running into a lot of issues trying to use static files and getting them to work with the development server.

I've been using the link: https://docs.djangoproject.com/en/1.4/howto/static-files/#staticfiles-development

When I run the development server, I notice that my CSS files are not getting pulled in but they are specified with the correct directory implying that Django is not finding my static files folder. My folder is defined in the project directory fold as 'static' and contains a folder called 'css' with 'bootstrap.css'.

When I look at the page source, I see:

<link href="css/bootstrap.css" rel="stylesheet">

but I can't view the CSS implying a problem with finding the correct directory.

What I added in settings was

STATICFILES_DIRS = (
    'static',
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

my dir structure: mysite/static/css/bootstrap.css

Thanks for any help :D

EDIT: Also if I can put non-existent directories into STATICFILES_DIR in settings.py without triggering an error in debug mode; does that imply that I have not configured Django to even look for static directories?

EDIT: I've also added a RequestContext to my views.py but it did not work out.

Upvotes: 0

Views: 113

Answers (1)

1: Make sure settings.DEBUG is True

2: Give absolute path to directory that contains static media. In this case, /PATH/TO/mysite/static/

3: Make sure calls to static files actually point to settings.STATIC_URL

Your example points to relative url css/bootstrap.css. It should probably point to {{ STATIC_URL }}css/bootstrap.css unless you got lucky and your page is routed at a URL that matches your STATIC_URL exactly.

With condition 1 and 2 met, static media is served AT settings.STATIC_URL FROM settings.STATICFILES_DIRS and other staticfiles finders.

Upvotes: 1

Related Questions