How to link a main.css to all Django templates? [closed]

Tags: python,css,django

Problem :

I want to be able to call classes in my main.css from all templates I have in Django. Currently, I have it stored in app_name/static/css/main.css. How do I link this to the templates so that I can simply add a class to an html element and have the class apply?

Solution :

I would use a base template containing all your common stuff (JQuery, main.css).

So, you will have a template called base.html will all the basic stuff and placeholders for specific pages content:

    <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}/css/main.css">
    {% block additional_header %}
    {% endblock %}
    {% block content %}
    {% endblock %}

Then, your actual page will be a template with something like this:

{% extends 'base.html' %}
{% block content %}
This is specific content for your page
{% endblock %}

Checkout Django's official documentation. Look for the section titled Template Inheritance.

    CSS Howto..

    How to apply CSS changes for the last

    element of the 3rd div class span8

    How to get actual (not original) height of a CSS-rotated element

    How to use the CSS :not selector for classes further up the DOM tree

    How to Make a Picture rotate Continuously? [closed]

    Do I need to use float:clear to have content show where I want it to show?

    How to get a style attribute from a CSS class by javascript/jQuery?

    How to hide a segment of my website using PHP

    How to keep an :active css style after clicking a link?

    How to pass a Rails variable into a view's CSS that must be refreshed dynamically (every 60 seconds)?

    how to make a div transparent without affecting the child in CSS 3?

    How to make an image appear over another image when mouse hovers with css3?

    CSS: How to set up gradient background cross browser (only missing IE8 and IE9)

    How to style my HTML form using CSS

    How to apply same event to multiple buttons?

    How do I add a the bootstrap 'form-control' class to a select using the Simple_Form gem?

    How to use an existing source map to compile scss to css?

    How to slowly move header while user scrolls the page?

    how to Load a css file for html page android web view

    How to apply CSS width to a submit input on Firefox?

    How to position footer correctly with css?

    How can I make a similar shape to a parallelogram in css?

    How to include several nested CSS classes into rails .erb file?

    How to find out an element with id partially matched, and change its css style?

    How to display block from left to right in css

    How can I prevent wild scrolling when a fixed position text input form field gains focus?

    how can I position my img right?

    Learning Bootstrap Thumbnails…why is that bullet showing?

    How can I make a button-link, as Like in Facebook?

    Multiple buttons in CSS + Button with an image not showing properly

    How to place div on top of responsive rotated div?