0

This is a bit embarrassing, but I don't know how to solve this problem:

First off, my project directory looks like this (there are more directories, but we aren't concerned with them):

projectfolder/
   wsgi/
     openshift/
         templates/
             home/
                simple-sidebar.html
     static/
        css/
        fonts/
        js/

And the file we are concerned with is simple-sidebar.html which looks like the following :

{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">

<title>Starter Template for Bootstrap</title>

<!-- Bootstrap core CSS -->
<link href= "{% static "css/bootstrap.css" %}" rel="stylesheet">

<!-- Add custom CSS here -->
<link href="{% static "css/simple-sidebar.css" %}" rel="stylesheet">
<link href="{% static "font-awesome/css/font-awesome.min.css" %}" rel="stylesheet">

</head>

Now for some reason my static template tags are not working, but that's probably because I don't know how to set up my static template stuff in my settings.py:

STATIC_ROOT = os.path.join(PROJECT_DIR, '..', 'static')

STATIC_URL = '/static/'

STATICFILES_DIRS = ()    <--- dont know if I need this one?

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

PS: Also how would you do this without the {% static %} tag? I am not sure how my style sheets href would look like.

ApathyBear
  • 9,057
  • 14
  • 56
  • 90

1 Answers1

0

Try removing the dots from your STATIC_ROOT, for example

STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')

STATICFILES_DIRS are there for you if you'd like to map additional folders to your application that can be anywhere on your machine. When you run ./manage.py collectstatic you're essentially asking python to find all the files within said directories and drop them into the static folder defined in STATIC_ROOT

If you would like to map your files manually (without the static tag) you'd have to write out the full path of your file, for example /some/directory/path/css/style.css.

Lastly if you're running with DEBUG = True you are required to add your static and media urls to urls.py so there is an actual path in place. For example

from django.conf import settings

# ... your normal urlpatterns here

if settings.DEBUG:
    urlpatterns += patterns('',
        (r'^media/(?P<path>.*)$', 'django.views.static.serve', {
        'document_root': settings.MEDIA_ROOT}),
        (r'^static/(?P<path>.*)$', 'django.views.static.serve', {
        'document_root': settings.STATIC_ROOT}))
Hevlastka
  • 1,878
  • 2
  • 18
  • 29