How to get css and django working on live server


Tags: python,html,css,django

Problem :

You guys were able to help me with last issue involving Django so I thought I'd ask another that has been killing me for the past couple days!

I have a small one app project with about 6 different pages, and I can get them to show however my style.css is not "showing" on the web page, I have followed countless guides including the Django's website and I just can't seem to get this working correctly. Here are some files that I think are relevant:

public_html/mysite/nfl/templates/home.html:

{% load staticfiles %}
<!DOCTYPE HTML>
 <html lang="en">
  <head>
   <title> Draftr Home Page </title>
   <meta charset="utf-8">
   <meta name = "viewport" content="width=device-width, initial-scale=1">

<!-- Using Bootstrap 3 framework with permission from getbootstrap.com -->
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

    <!-- jQuery library -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

    <!-- Latest compiled JavaScript -->
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

    <!-- Custom Style Sheet -->
    <link href="{% static 'style.css' %}" rel="stylesheet" media="screen">

style.css is located here public_html/mysite/nfl/static AND /home/gobelogic/public_html/mysite/static(alongside admin/)

/home/gobelogic/public_html/mysite/mysite:

import os.path
import sys

PROJECT_ROOT = os.path.normpath(os.path.dirname(__file__))
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

INSTALLED_APPS = (
#other
'django.contrib.staticfiles',
'nfl'
)


TEMPLATE_DIRS = 
     "nfl/templates",

)

STATICFILES_DIRS = (
    '/home/gobelogic/public_html/mysite/nfl/static',
)
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static')

Ok I'm going to try and explain how I think django handles static files, please correct me where I'm wrong:

so in settings.py django is locating all static directories in my project and placing their contents in a single directory static/ next to manange.py(which is done when I run manage.py collectstatic

in the html file I tell django to load all the static files so that i can use them at the top by using {% load staticfiles %} and then i say which one in particular by using <link href="{% static 'style.css' %}" rel="stylesheet" media="screen"> by doing this, django uses the settings.py(?) to find where I put these static files and then loads up the stylesheet that way

Again I am running this on my production server so none of this is run through django built in server, idk if that matters or not

Thanks for any help

EDIT using django 1.8



Solution :

Since you are not using Django internal server (rightly so), you need to make your production web server aware of the static file location. There is an example in Django docs for Apache (https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/#serving-files). Even if you are not using apache, generally you need to make sure that /static/ or whatever your STATIC_URL points to is served from the place where your STATIC_ROOT points to.


    CSS Howto..

    How to get started with Compass/Sass on Mac – Invalid CSS error?

    D3js SVG open lines display a fill artifact, how to fix it?

    How do you make a sticky nav bar change colour when you scroll to a desired div?

    How to adjust the position a table to the bottom inside a DIV?

    How to Style Unique CSS Navigation Menu

    How to style the wp_list_page in wordpress?

    How to keep the HTML element aligned when clicked/focused?

    how to apply background transparency on a div (for an AJAX loading animation)?

    How to trigger the :active pseudoclass on keyboard 'enter' press? (using only CSS)

    How to make a progress bar

    How to align elements equally in a line in CSS/Bootstrap?

    How to apply CSS style which will be ignored for tfoot or last TR

    How to break a table with CSS diagonally or vertically?

    How do I insert an image in HTML so that its fills up the entire screen regardless of screen size?

    How to hide first 3 childs of UL using CSS

    How to make background image go in the “background” using CSS/HTML

    How to change radio button place & add line separator

    How to highlight one image over other using jquery css? [duplicate]

    how to resolve border-radius property issue in all versions of browsers? [duplicate]

    How to move all content (relative,absolute,…) down?

    How to make table td take the width of its content

    CSS: How to fake a :hover state?

    How to re-size a box with CSS or Javascript

    How to apply direction css attribute in list elements

    How to apply css for anchor tag inside table

    How to hide old styled version of select option? [duplicate]

    CSS question: How to fix several rendering issues on http://www.fareham.ac.uk

    How to change menu from on hover to on click

    How to make jQuery show() stay on page

    How to avoid AjaxMin removal for IE9 and below CSS hack