Django include template along with its css











up vote
0
down vote

favorite












I am trying to include a template - header.html into the main.html file. The header.html has its own css file. I have one choice- to link the css into the head of header.html and then include it. But it makes the code looks messier with many html tags in the same document. For instance, if I need to include another footer.html, again additional html tags will come to the main.html.



Another option is to simply put all the styles into one main.css file and include that in the base.html. But again it makes main.css harder to edit.



Is there any better solutions?



Thanks










share|improve this question






















  • One way is to make reusable class and id. It will take time first but can be helpful afterwards. Make similar kind of class for both header and footer. Add the common css file to static folder and import into base html. For body add extend tag.
    – Bidhan Majhi
    24 mins ago















up vote
0
down vote

favorite












I am trying to include a template - header.html into the main.html file. The header.html has its own css file. I have one choice- to link the css into the head of header.html and then include it. But it makes the code looks messier with many html tags in the same document. For instance, if I need to include another footer.html, again additional html tags will come to the main.html.



Another option is to simply put all the styles into one main.css file and include that in the base.html. But again it makes main.css harder to edit.



Is there any better solutions?



Thanks










share|improve this question






















  • One way is to make reusable class and id. It will take time first but can be helpful afterwards. Make similar kind of class for both header and footer. Add the common css file to static folder and import into base html. For body add extend tag.
    – Bidhan Majhi
    24 mins ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am trying to include a template - header.html into the main.html file. The header.html has its own css file. I have one choice- to link the css into the head of header.html and then include it. But it makes the code looks messier with many html tags in the same document. For instance, if I need to include another footer.html, again additional html tags will come to the main.html.



Another option is to simply put all the styles into one main.css file and include that in the base.html. But again it makes main.css harder to edit.



Is there any better solutions?



Thanks










share|improve this question













I am trying to include a template - header.html into the main.html file. The header.html has its own css file. I have one choice- to link the css into the head of header.html and then include it. But it makes the code looks messier with many html tags in the same document. For instance, if I need to include another footer.html, again additional html tags will come to the main.html.



Another option is to simply put all the styles into one main.css file and include that in the base.html. But again it makes main.css harder to edit.



Is there any better solutions?



Thanks







django inheritance django-templates include






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 1 hour ago









jeff

131112




131112












  • One way is to make reusable class and id. It will take time first but can be helpful afterwards. Make similar kind of class for both header and footer. Add the common css file to static folder and import into base html. For body add extend tag.
    – Bidhan Majhi
    24 mins ago


















  • One way is to make reusable class and id. It will take time first but can be helpful afterwards. Make similar kind of class for both header and footer. Add the common css file to static folder and import into base html. For body add extend tag.
    – Bidhan Majhi
    24 mins ago
















One way is to make reusable class and id. It will take time first but can be helpful afterwards. Make similar kind of class for both header and footer. Add the common css file to static folder and import into base html. For body add extend tag.
– Bidhan Majhi
24 mins ago




One way is to make reusable class and id. It will take time first but can be helpful afterwards. Make similar kind of class for both header and footer. Add the common css file to static folder and import into base html. For body add extend tag.
– Bidhan Majhi
24 mins ago












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Make a folder as templates under root directory of your project and add below line in settings.py file to define the template path.



TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')], #mainly this line
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]


and



STATIC_URL = '/static/'    
STATIC = os.path.join(BASE_DIR, 'static')


After it make base.html file and enter all the js and css file over here. That will reflect to all the project.



{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<meta http-equiv="cache-control" content="no-cache, must-revalidate, post-check=0, pre-check=0" />
<title>Test </title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="description" content="Test">
<link rel="shortcut icon" type="image/png" href="{% static 'images/small.png' %}"/>
<link rel="stylesheet" href="{% static 'css/lightbox.css' %}" type="text/css" />
<link rel="stylesheet" href="{% static 'css/style.css' %}" type="text/css" />
<link rel="stylesheet" href="{% static 'css/responsive.css' %}" type="text/css" />
<!-- more css files -->
</head>
<body>
{% block pagecontent %}
{% endblock %}

</body>
<script type="text/javascript" src="{% static 'js/asset/jquery-2.1.3.min.js' %}"></script>
<script src="static 'custom.js' %}"></script>
<!-- more js files -->
</html>





share|improve this answer























  • Screenshots aren't any more useful in answers than they are in questions. Post code here as text.
    – Daniel Roseman
    39 mins ago











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371577%2fdjango-include-template-along-with-its-css%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Make a folder as templates under root directory of your project and add below line in settings.py file to define the template path.



TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')], #mainly this line
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]


and



STATIC_URL = '/static/'    
STATIC = os.path.join(BASE_DIR, 'static')


After it make base.html file and enter all the js and css file over here. That will reflect to all the project.



{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<meta http-equiv="cache-control" content="no-cache, must-revalidate, post-check=0, pre-check=0" />
<title>Test </title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="description" content="Test">
<link rel="shortcut icon" type="image/png" href="{% static 'images/small.png' %}"/>
<link rel="stylesheet" href="{% static 'css/lightbox.css' %}" type="text/css" />
<link rel="stylesheet" href="{% static 'css/style.css' %}" type="text/css" />
<link rel="stylesheet" href="{% static 'css/responsive.css' %}" type="text/css" />
<!-- more css files -->
</head>
<body>
{% block pagecontent %}
{% endblock %}

</body>
<script type="text/javascript" src="{% static 'js/asset/jquery-2.1.3.min.js' %}"></script>
<script src="static 'custom.js' %}"></script>
<!-- more js files -->
</html>





share|improve this answer























  • Screenshots aren't any more useful in answers than they are in questions. Post code here as text.
    – Daniel Roseman
    39 mins ago















up vote
0
down vote













Make a folder as templates under root directory of your project and add below line in settings.py file to define the template path.



TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')], #mainly this line
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]


and



STATIC_URL = '/static/'    
STATIC = os.path.join(BASE_DIR, 'static')


After it make base.html file and enter all the js and css file over here. That will reflect to all the project.



{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<meta http-equiv="cache-control" content="no-cache, must-revalidate, post-check=0, pre-check=0" />
<title>Test </title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="description" content="Test">
<link rel="shortcut icon" type="image/png" href="{% static 'images/small.png' %}"/>
<link rel="stylesheet" href="{% static 'css/lightbox.css' %}" type="text/css" />
<link rel="stylesheet" href="{% static 'css/style.css' %}" type="text/css" />
<link rel="stylesheet" href="{% static 'css/responsive.css' %}" type="text/css" />
<!-- more css files -->
</head>
<body>
{% block pagecontent %}
{% endblock %}

</body>
<script type="text/javascript" src="{% static 'js/asset/jquery-2.1.3.min.js' %}"></script>
<script src="static 'custom.js' %}"></script>
<!-- more js files -->
</html>





share|improve this answer























  • Screenshots aren't any more useful in answers than they are in questions. Post code here as text.
    – Daniel Roseman
    39 mins ago













up vote
0
down vote










up vote
0
down vote









Make a folder as templates under root directory of your project and add below line in settings.py file to define the template path.



TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')], #mainly this line
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]


and



STATIC_URL = '/static/'    
STATIC = os.path.join(BASE_DIR, 'static')


After it make base.html file and enter all the js and css file over here. That will reflect to all the project.



{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<meta http-equiv="cache-control" content="no-cache, must-revalidate, post-check=0, pre-check=0" />
<title>Test </title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="description" content="Test">
<link rel="shortcut icon" type="image/png" href="{% static 'images/small.png' %}"/>
<link rel="stylesheet" href="{% static 'css/lightbox.css' %}" type="text/css" />
<link rel="stylesheet" href="{% static 'css/style.css' %}" type="text/css" />
<link rel="stylesheet" href="{% static 'css/responsive.css' %}" type="text/css" />
<!-- more css files -->
</head>
<body>
{% block pagecontent %}
{% endblock %}

</body>
<script type="text/javascript" src="{% static 'js/asset/jquery-2.1.3.min.js' %}"></script>
<script src="static 'custom.js' %}"></script>
<!-- more js files -->
</html>





share|improve this answer














Make a folder as templates under root directory of your project and add below line in settings.py file to define the template path.



TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')], #mainly this line
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]


and



STATIC_URL = '/static/'    
STATIC = os.path.join(BASE_DIR, 'static')


After it make base.html file and enter all the js and css file over here. That will reflect to all the project.



{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<meta http-equiv="cache-control" content="no-cache, must-revalidate, post-check=0, pre-check=0" />
<title>Test </title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="description" content="Test">
<link rel="shortcut icon" type="image/png" href="{% static 'images/small.png' %}"/>
<link rel="stylesheet" href="{% static 'css/lightbox.css' %}" type="text/css" />
<link rel="stylesheet" href="{% static 'css/style.css' %}" type="text/css" />
<link rel="stylesheet" href="{% static 'css/responsive.css' %}" type="text/css" />
<!-- more css files -->
</head>
<body>
{% block pagecontent %}
{% endblock %}

</body>
<script type="text/javascript" src="{% static 'js/asset/jquery-2.1.3.min.js' %}"></script>
<script src="static 'custom.js' %}"></script>
<!-- more js files -->
</html>






share|improve this answer














share|improve this answer



share|improve this answer








edited 29 mins ago

























answered 52 mins ago









Anoop Kumar

14713




14713












  • Screenshots aren't any more useful in answers than they are in questions. Post code here as text.
    – Daniel Roseman
    39 mins ago


















  • Screenshots aren't any more useful in answers than they are in questions. Post code here as text.
    – Daniel Roseman
    39 mins ago
















Screenshots aren't any more useful in answers than they are in questions. Post code here as text.
– Daniel Roseman
39 mins ago




Screenshots aren't any more useful in answers than they are in questions. Post code here as text.
– Daniel Roseman
39 mins ago


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371577%2fdjango-include-template-along-with-its-css%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith