Reputation: 41
I am new in django, my problem is how to give a link to css and js
{% load staticfiles %}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome</title>
<link href="css/templatemo_style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="{% static "css/templatemo_style.css" %}" />
<script type="text/javascript" src="js/jquery.min.js"></script>
css and js not load from actual path, dont know how to use actual path of static folder in html i am trying to use
import os
#DIRNAME = os.path.abspath(os.path.dirname(__file__))
DIRNAME = os.path.dirname(__file__)
But it give me the wrong path
i am providing a brief description:
TEMPLATE_DIRS = (
os.path.join(DIRNAME, 'static/'),
}
my url is
http://127.0.0.1:8000/blog/home/
error showing
Template-loader postmortem
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
D:\Eclipse_JEE_new_workspace\testing\testing\static\index.html (File does not exist)
Using loader django.template.loaders.app_directories.Loader:
C:\Python27\lib\site-packages\django\contrib\auth\templates\index.html (File does not exist)
C:\Python27\lib\site-packages\django\contrib\admin\templates\index.html (File does not exist)
It showing:
D:\Eclipse_JEE_new_workspace\testing\testing\static\index.html
but actual
If i moved static folder in testing folder, its me an html page without css and js link
D:\Eclipse_JEE_new_workspace\testing\static\index.html
Sorry for more description before now situation is:
when page load css link give me an error 404 but same position index.html page load
how to include css/js?
In current situation, i am using
{% include 'header.html' %}
to include in index.html
Upvotes: 2
Views: 2881
Reputation: 14180
Template files should go in the templates
folder. And DIRNAME
has the path to the settings.py
.
Should probably be something like:
DIRNAME = os.path.join(os.path.dirname(__file__), '..')
TEMPLATE_DIRS = (
os.path.join(DIRNAME, 'templates/'),
}
And make sure your index.html
is in the templates
folder.
Upvotes: 1