0

I have gotten it to now work locally thanks to @Selcuk by adding to the bottom of the settings.py STATICFILES_FINDERS & STATICFILES_DIRS. The page works on with stylesheet locally BUT once I push to my heroku web app it fails to run the stylesheet.

Code for Base Template

<!DOCTYPE html>
<html>
<head>
        <title>ToolShare » Mohammad Daraghmeh</title>
        <!-- Fav Icon -->
        <link rel="shortcut icon" href="http://bit.ly/1xDbduz" type="image/x-icon">
            <link rel="icon" href="http://bit.ly/1xDbduz" type="image/x-icon">
        <!-- Latest compiled and minified CSS -->
        <link href="//maxcdn.bootstrapcdn.com/bootswatch/3.3.4/united/bootstrap.min.css" rel="stylesheet">
        <!-- Font-Awesome -->
        <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
        <!-- Animate -->
        <link href="//cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.6/animate.min.css" rel="stylesheet">
        <!-- Latest jQuery -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
        <!-- Latest compiled and minified JavaScript -->
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
        <!-- Custom Css -->
        <link href="{{ STATIC_URL }}css/stylesheet.css" rel="stylesheet" type="text/css">

</head>

settings.py

"""
Django settings for toolshare project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

TEMPLATE_DIRS  = [os.path.join(BASE_DIR, 'templates')]
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '_0ut&uh=ou!jdw3e(ys@=x)k_)uu5d-if4ishx8lrjmiu_ma-q'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'toolshare',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'toolshare.urls'

WSGI_APPLICATION = 'toolshare.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'EST'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
STATIC_URL = '/static/'

STATICFILES_FINDERS = (
    "django.contrib.staticfiles.finders.FileSystemFinder",
    #"django.contrib.staticfiles.finders.AppDirectoriesFinder"
)

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

Photo of CMD Is the 304 normal for a CSS, I am guessing yes for it is not being modifited. enter image description here

TheAce
  • 122
  • 1
  • 16

2 Answers2

1

Your css directory is under your static directory. You should either use:

<link href="{{ STATIC_URL }}css/stylesheet.css" rel="stylesheet" type="text/css">

or put

{% load staticfiles %}

on top of your HTML file, then use

<link href="{% static 'css/stylesheet.css' %}" rel="stylesheet" type="text/css">
Selcuk
  • 57,004
  • 12
  • 102
  • 110
  • The first method did not work either did the other one. I have both `STATIC_URL = '/static/'` and `'django.contrib.staticfiles',` My dir. is as follows: ToolShare\templates\partials\stylesheet.css With the code {% load staticfiles %} – TheAce Mar 27 '15 at 20:27
  • You should not put your static content (css, js, images, etc) into template directories. Can you update your question and post your `settings.py`? – Selcuk Mar 27 '15 at 20:53
  • If you are using Heroku with Gunicorn you need to use a static file serving app, like Whitenoise. See Heroku docs: https://devcenter.heroku.com/articles/django-assets#whitenoise – Selcuk Mar 27 '15 at 22:14
  • You should also consider adding `STATIC_ROOT = os.path.join(BASE_DIR, 'static')` to your `settings.py` – Selcuk Mar 27 '15 at 22:36
-1

You have to create a static directory for your static files (css, js, etc)

Then, set your static directory in Django settings (STATIC_URL variable)

Eventually, put {% load static %} in the top of your template.