2

I've read the official Django Docs and many other posts here in SO. Still I'm unable to figure out the way to load my CSS files in HTML pages. I'm running Django 1.4. Here is my whole structure of mysite project having auth as the app.

mysite/
      manage.py
      settings.py
      __init__.py
      urls.py
      auth/
          __init__.py
          forms.py
          models.py
          views.py
      templates/
               index.html
               home.html
      media/
           common.css

How can I load my common.css file in index and home template files?

xan
  • 4,640
  • 13
  • 50
  • 83
  • 2
    Hope this may help : [reference 1](http://stackoverflow.com/questions/10042469/django-1-4-static-files-problems-and-dont-render-at-other-urls-of-my-project) [reference 2](http://stackoverflow.com/questions/9026409/django-site-in-developement-css-not-loading-for-all-pages) – Surinder ツ Dec 25 '12 at 12:09

1 Answers1

3

Take a look at static files: https://docs.djangoproject.com/en/dev/howto/static-files/

You need to:

  1. add django.contrib.staticfiles to your installed apps
  2. put your files in the static directory
  3. set STATIC_ROOT and STATIC_URL in your settings
  4. use the STATIC_URL variable or the static templatetag in your templates

{% load staticfiles %} and then <link href="{% static "common.css" %}" rel="stylesheet" type="text/css"/>

In your production environment you'll then need to collect the static files

StefanoP
  • 3,798
  • 2
  • 19
  • 26