Django app not loading CSS background-image, but image loads with inline styling. Is there a fix for this?
up vote
0
down vote
favorite
** EDIT ** SOLVED
I'm using bootstrap_admin app for my Django admin page. If you are using bootstrap_admin app for your Django Admin page, this might come in handy for customizing the sidebar.
TLDR:
Sidebar.html doesn't see my custom.css file, only base.css, so I had to add everything to base.css
The long version:
Look below the break to see my original problem.
So essentially, bootstrap admin has a template tag for the sidebar. This sidebar is customized with sidebar.html template, but it's not really a template as I thought; it's actually called into a template using a couple of commands, such as :
{% display_sidebar_menu cl.has_filters as is_displaying_menu %}
and
{% block sidebar_menu %}
{% render_menu_app_list %}
Because of this, for some reason the sidebar.html file doesn't see my custom.css file, even though it comes after the base.css file link in the base.html head.
Anyway, because of that reason, I found that I had to put my custom classes into the base.css file directly. Fortunately the file is pretty small and easy to maintain, so this isn't a big deal.
Background images are now showing correctly, and I don't have to use any inline styles, which is great.
For those who took the time to comment, thank you for your time. Hopefully my mistake helps someone else in the future.
As the title states.
I've run into an interesting problem. This is related to css background images. I am loading the app names and their models in a sidebar menu, and for some reason the images just won't load.
I added the images in the static folder for the app. The code in the css file is the following:
/* App Buttons and Icons */
#servers_icon {
background-image: url("/static/bootstrap_admin/img/icon_servers_copy.png") no-repeat;
}
#sensors_icon {
background-image: url("/static/bootstrap_admin/img/icon_sensors_copy.png") no-repeat;
}
Note the path.
For some reason, django is refusing the load these files. The css file is being loaded and actively used by the app. The ID names are correct. However, the images just will not load.
However, if I put them inline in the HTML file:
<li style="background-image: url('/static/bootstrap_admin/img/icon_{{ app.app_label }}_copy.png'); background-repeat: no-repeat;" {% if app.app_url == current_url %}class="active"{% endif %}>
<a href="{{ app.app_url }}" class="section" title="Models in the {{ name }} application">
{{ app.name }}
</a>
</li>
Then the images load. Note that the path is the same.
{{app.app_label}} is part of the in-template for loop that populates the menu. The label name and file name matches. In fact, the file name was renamed to match the app label name.
Anyway, I have checked numerous sources and can't seem to find a fix for this. For now, I will keep the style in-line, but I would like to revert back to using the CSS file if possible. I really dislike using inline styling.
Please note that this is development code. I'm honestly stumped here, and I have no idea what to do at this point beyond continuing to use inline styling just to load the icons.
css django twitter-bootstrap
add a comment |
up vote
0
down vote
favorite
** EDIT ** SOLVED
I'm using bootstrap_admin app for my Django admin page. If you are using bootstrap_admin app for your Django Admin page, this might come in handy for customizing the sidebar.
TLDR:
Sidebar.html doesn't see my custom.css file, only base.css, so I had to add everything to base.css
The long version:
Look below the break to see my original problem.
So essentially, bootstrap admin has a template tag for the sidebar. This sidebar is customized with sidebar.html template, but it's not really a template as I thought; it's actually called into a template using a couple of commands, such as :
{% display_sidebar_menu cl.has_filters as is_displaying_menu %}
and
{% block sidebar_menu %}
{% render_menu_app_list %}
Because of this, for some reason the sidebar.html file doesn't see my custom.css file, even though it comes after the base.css file link in the base.html head.
Anyway, because of that reason, I found that I had to put my custom classes into the base.css file directly. Fortunately the file is pretty small and easy to maintain, so this isn't a big deal.
Background images are now showing correctly, and I don't have to use any inline styles, which is great.
For those who took the time to comment, thank you for your time. Hopefully my mistake helps someone else in the future.
As the title states.
I've run into an interesting problem. This is related to css background images. I am loading the app names and their models in a sidebar menu, and for some reason the images just won't load.
I added the images in the static folder for the app. The code in the css file is the following:
/* App Buttons and Icons */
#servers_icon {
background-image: url("/static/bootstrap_admin/img/icon_servers_copy.png") no-repeat;
}
#sensors_icon {
background-image: url("/static/bootstrap_admin/img/icon_sensors_copy.png") no-repeat;
}
Note the path.
For some reason, django is refusing the load these files. The css file is being loaded and actively used by the app. The ID names are correct. However, the images just will not load.
However, if I put them inline in the HTML file:
<li style="background-image: url('/static/bootstrap_admin/img/icon_{{ app.app_label }}_copy.png'); background-repeat: no-repeat;" {% if app.app_url == current_url %}class="active"{% endif %}>
<a href="{{ app.app_url }}" class="section" title="Models in the {{ name }} application">
{{ app.name }}
</a>
</li>
Then the images load. Note that the path is the same.
{{app.app_label}} is part of the in-template for loop that populates the menu. The label name and file name matches. In fact, the file name was renamed to match the app label name.
Anyway, I have checked numerous sources and can't seem to find a fix for this. For now, I will keep the style in-line, but I would like to revert back to using the CSS file if possible. I really dislike using inline styling.
Please note that this is development code. I'm honestly stumped here, and I have no idea what to do at this point beyond continuing to use inline styling just to load the icons.
css django twitter-bootstrap
(Didn’t you ask the same thing earlier today already?) What does the browser console say? What do you see when you inspect the element in question?
– misorude
Nov 20 at 12:58
Did you "collectstatic"?
– JLucasRS
Nov 20 at 13:33
@misorude No, but perhaps someone with a similar name did? Anyway, I've figured it out and I feel dumb. I'm fixing my code now, but I will give a full explanation on what I found out once I fix it up.
– Nathan
Nov 20 at 13:38
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
** EDIT ** SOLVED
I'm using bootstrap_admin app for my Django admin page. If you are using bootstrap_admin app for your Django Admin page, this might come in handy for customizing the sidebar.
TLDR:
Sidebar.html doesn't see my custom.css file, only base.css, so I had to add everything to base.css
The long version:
Look below the break to see my original problem.
So essentially, bootstrap admin has a template tag for the sidebar. This sidebar is customized with sidebar.html template, but it's not really a template as I thought; it's actually called into a template using a couple of commands, such as :
{% display_sidebar_menu cl.has_filters as is_displaying_menu %}
and
{% block sidebar_menu %}
{% render_menu_app_list %}
Because of this, for some reason the sidebar.html file doesn't see my custom.css file, even though it comes after the base.css file link in the base.html head.
Anyway, because of that reason, I found that I had to put my custom classes into the base.css file directly. Fortunately the file is pretty small and easy to maintain, so this isn't a big deal.
Background images are now showing correctly, and I don't have to use any inline styles, which is great.
For those who took the time to comment, thank you for your time. Hopefully my mistake helps someone else in the future.
As the title states.
I've run into an interesting problem. This is related to css background images. I am loading the app names and their models in a sidebar menu, and for some reason the images just won't load.
I added the images in the static folder for the app. The code in the css file is the following:
/* App Buttons and Icons */
#servers_icon {
background-image: url("/static/bootstrap_admin/img/icon_servers_copy.png") no-repeat;
}
#sensors_icon {
background-image: url("/static/bootstrap_admin/img/icon_sensors_copy.png") no-repeat;
}
Note the path.
For some reason, django is refusing the load these files. The css file is being loaded and actively used by the app. The ID names are correct. However, the images just will not load.
However, if I put them inline in the HTML file:
<li style="background-image: url('/static/bootstrap_admin/img/icon_{{ app.app_label }}_copy.png'); background-repeat: no-repeat;" {% if app.app_url == current_url %}class="active"{% endif %}>
<a href="{{ app.app_url }}" class="section" title="Models in the {{ name }} application">
{{ app.name }}
</a>
</li>
Then the images load. Note that the path is the same.
{{app.app_label}} is part of the in-template for loop that populates the menu. The label name and file name matches. In fact, the file name was renamed to match the app label name.
Anyway, I have checked numerous sources and can't seem to find a fix for this. For now, I will keep the style in-line, but I would like to revert back to using the CSS file if possible. I really dislike using inline styling.
Please note that this is development code. I'm honestly stumped here, and I have no idea what to do at this point beyond continuing to use inline styling just to load the icons.
css django twitter-bootstrap
** EDIT ** SOLVED
I'm using bootstrap_admin app for my Django admin page. If you are using bootstrap_admin app for your Django Admin page, this might come in handy for customizing the sidebar.
TLDR:
Sidebar.html doesn't see my custom.css file, only base.css, so I had to add everything to base.css
The long version:
Look below the break to see my original problem.
So essentially, bootstrap admin has a template tag for the sidebar. This sidebar is customized with sidebar.html template, but it's not really a template as I thought; it's actually called into a template using a couple of commands, such as :
{% display_sidebar_menu cl.has_filters as is_displaying_menu %}
and
{% block sidebar_menu %}
{% render_menu_app_list %}
Because of this, for some reason the sidebar.html file doesn't see my custom.css file, even though it comes after the base.css file link in the base.html head.
Anyway, because of that reason, I found that I had to put my custom classes into the base.css file directly. Fortunately the file is pretty small and easy to maintain, so this isn't a big deal.
Background images are now showing correctly, and I don't have to use any inline styles, which is great.
For those who took the time to comment, thank you for your time. Hopefully my mistake helps someone else in the future.
As the title states.
I've run into an interesting problem. This is related to css background images. I am loading the app names and their models in a sidebar menu, and for some reason the images just won't load.
I added the images in the static folder for the app. The code in the css file is the following:
/* App Buttons and Icons */
#servers_icon {
background-image: url("/static/bootstrap_admin/img/icon_servers_copy.png") no-repeat;
}
#sensors_icon {
background-image: url("/static/bootstrap_admin/img/icon_sensors_copy.png") no-repeat;
}
Note the path.
For some reason, django is refusing the load these files. The css file is being loaded and actively used by the app. The ID names are correct. However, the images just will not load.
However, if I put them inline in the HTML file:
<li style="background-image: url('/static/bootstrap_admin/img/icon_{{ app.app_label }}_copy.png'); background-repeat: no-repeat;" {% if app.app_url == current_url %}class="active"{% endif %}>
<a href="{{ app.app_url }}" class="section" title="Models in the {{ name }} application">
{{ app.name }}
</a>
</li>
Then the images load. Note that the path is the same.
{{app.app_label}} is part of the in-template for loop that populates the menu. The label name and file name matches. In fact, the file name was renamed to match the app label name.
Anyway, I have checked numerous sources and can't seem to find a fix for this. For now, I will keep the style in-line, but I would like to revert back to using the CSS file if possible. I really dislike using inline styling.
Please note that this is development code. I'm honestly stumped here, and I have no idea what to do at this point beyond continuing to use inline styling just to load the icons.
css django twitter-bootstrap
css django twitter-bootstrap
edited Nov 20 at 14:13
asked Nov 20 at 12:37
Nathan
821114
821114
(Didn’t you ask the same thing earlier today already?) What does the browser console say? What do you see when you inspect the element in question?
– misorude
Nov 20 at 12:58
Did you "collectstatic"?
– JLucasRS
Nov 20 at 13:33
@misorude No, but perhaps someone with a similar name did? Anyway, I've figured it out and I feel dumb. I'm fixing my code now, but I will give a full explanation on what I found out once I fix it up.
– Nathan
Nov 20 at 13:38
add a comment |
(Didn’t you ask the same thing earlier today already?) What does the browser console say? What do you see when you inspect the element in question?
– misorude
Nov 20 at 12:58
Did you "collectstatic"?
– JLucasRS
Nov 20 at 13:33
@misorude No, but perhaps someone with a similar name did? Anyway, I've figured it out and I feel dumb. I'm fixing my code now, but I will give a full explanation on what I found out once I fix it up.
– Nathan
Nov 20 at 13:38
(Didn’t you ask the same thing earlier today already?) What does the browser console say? What do you see when you inspect the element in question?
– misorude
Nov 20 at 12:58
(Didn’t you ask the same thing earlier today already?) What does the browser console say? What do you see when you inspect the element in question?
– misorude
Nov 20 at 12:58
Did you "collectstatic"?
– JLucasRS
Nov 20 at 13:33
Did you "collectstatic"?
– JLucasRS
Nov 20 at 13:33
@misorude No, but perhaps someone with a similar name did? Anyway, I've figured it out and I feel dumb. I'm fixing my code now, but I will give a full explanation on what I found out once I fix it up.
– Nathan
Nov 20 at 13:38
@misorude No, but perhaps someone with a similar name did? Anyway, I've figured it out and I feel dumb. I'm fixing my code now, but I will give a full explanation on what I found out once I fix it up.
– Nathan
Nov 20 at 13:38
add a comment |
active
oldest
votes
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393166%2fdjango-app-not-loading-css-background-image-but-image-loads-with-inline-styling%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393166%2fdjango-app-not-loading-css-background-image-but-image-loads-with-inline-styling%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
(Didn’t you ask the same thing earlier today already?) What does the browser console say? What do you see when you inspect the element in question?
– misorude
Nov 20 at 12:58
Did you "collectstatic"?
– JLucasRS
Nov 20 at 13:33
@misorude No, but perhaps someone with a similar name did? Anyway, I've figured it out and I feel dumb. I'm fixing my code now, but I will give a full explanation on what I found out once I fix it up.
– Nathan
Nov 20 at 13:38