How to make a basic template use static files and make other templates that inherit the basic template to use the same static files?
As I read in the django documentation, he writes on how to use static files that are used for a specific application. But I canβt find a way to make it use static files from outside the application.
This application inherits everything, but static files.
My .py settings:
STATIC_URL = '/static/' # Additional locations of static files STATICFILES_DIRS = ( # 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. ) # List of finder classes that know how to find static files in # various locations. STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', # 'django.contrib.staticfiles.finders.DefaultStorageFinder', ) INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'south', 'myproject.apps.finance', 'myproject.apps.base', 'django.contrib.admin', ) TEMPLATE_CONTEXT_PROCESSORS = ( 'django.core.context_processors.debug', 'django.core.context_processors.i18n', 'django.core.context_processors.media', 'django.core.context_processors.static', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', )
These are my current homepage settings:
URL for the main page:
from django.conf.urls import patterns, include, url from myproject.views import hello urlpatterns = patterns('', ('', hello), )
home page view:
from django.shortcuts import render_to_response from django.http import Http404, HttpResponse import datetime def hello(request): hello = "Hello World" return render_to_response('home/home.html', {'hello': hello})
home page template:
{% extends "base/base.html" %} {% block title %} My Homepage {% endblock %} {% block content %} <p>I say {{ hello }}</p> {% endblock %}
base template:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html lang="en"> <head> <link rel="stylesheet" href="{{ STATIC_URL }}/css/style.css"> <title>{% block title %}{% endblock %}</title> </head> <body> <h1>My Personal Finance Site</h1> {% block content %}{% endblock %} {% block footer %} <section class="divider1"> <p>Thanks for visiting my site.</p> <p>All rights reserved</p> </section> {% endblock %} </body> </html>
my CSS file is in an empty project called base. But I think that there may be a better way to use static files outside this application.
So, what would be the best way to associate a basic template with a css file to make other templates that are in the database to get the same css file configuration?