Reputation: 679
I'm new to Django, and i'm having hard time including css styles in a template.
I read this and tried to do the same but it's not working for me.
my Template:
{% load static %}<html><head><link href="{% get_static_prefix %}/style.css" rel='stylesheet' type='text/css' /></head><body>
the HTML i get:
<head><link href="C:/Users/Nayish/workspace/am/src/am/static/style.css"rel='stylesheet'type='text/css' /></head>
Note that this is the folder containing my css.
Thanks, Boris.
Upvotes: 3
Views: 2975
Reputation: 31868
Make sure you haven't mixed up the STATIC_ROOT
and STATIC_URL
settings.
STATIC_ROOT
defines where the files are on the storage system (usually your local hard disc for local development), while STATIC_URL
defines the URL from where the server serves them. The second one is usually referred to in templates, and it is also the value that the {% get_static_prefix %}
template tag returns.
Upvotes: 3
Reputation: 58602
I am guessing you aren't using static css sheets. I always just do:
<html>
<head>
{%block stylesheet %}
<style type="text/css" title="currentStyle">
@import "{{MEDIA_URL}}css/style.css";
</style>
{% endblock stylesheet%}
....
I then set my Media root, and store the files as
MEDIA_ROOT=<fullyquallified patyh>/Media/css/<css files>
MEDIA_URL=http://localhost/mysite/
It should be noted that STATIC_URL
defaults to MEDIA_URL
if its not defined.
Upvotes: 0