Including css in Django

I'm new to Django, and it's hard for me to work with CSS styles in a template.

I read this one and tried to do the same, but it does not work for me.

my Template:

{% load static %}<html><head><link href="{% get_static_prefix %}/style.css" rel='stylesheet' type='text/css' /></head><body>

HTML I get:

<head><link href="C:/Users/Nayish/workspace/am/src/am/static/style.css"rel='stylesheet'type='text/css' /></head>

Please note that this is the folder containing my css.

Thank you Boris.

+3
source share
2 answers

I assume that you are not using static css lists. I always just do:

<html>
<head>
            {%block stylesheet %}
               <style type="text/css" title="currentStyle"> 
                   @import "{{MEDIA_URL}}css/style.css";
               </style>
            {% endblock stylesheet%}
   ....

Then I set my media root and save the files as

 MEDIA_ROOT=<fullyquallified patyh>/Media/css/<css files>
 MEDIA_URL=http://localhost/mysite/

It should be noted that STATIC_URLthe default is MEDIA_URLif it is not defined.

0
source

Make sure that you are not confused STATIC_ROOTand STATIC_URL.

STATIC_ROOT , ( ), STATIC_URL URL-, . , , {% get_static_prefix %}.

+3

All Articles