Django 2 Images from STATIC_URL is not loading in Css2019 Community Moderator ElectionDoes Django scale?Django external css file problemcannot access static files in DjangoLink to a django static file doesnt workHow to link my css, js and image file link in djangoDjango : extract image from database and display in templateBest configuration for Django staticfilesLinking up CSS (and static files in general) to html in DjangoDisplay images that reside in a folder outside of django project folderDjango static file is not loading in my computer (windows 10) but its working on others computer (windows 10)
Specifying a starting column with colortbl package and xcolor
This Alpine town?
Rationale to prefer local variables over instance variables?
Can we track matter through time by looking at different depths in space?
Should I take out a loan for a friend to invest on my behalf?
What's the 'present simple' form of the word "нашла́" in 3rd person singular female?
Can I negotiate a patent idea for a raise, under French law?
Why couldn't the separatists legally leave the Republic?
Do cubics always have one real root?
Which classes are needed to have access to every spell in the PHB?
Can one live in the U.S. and not use a credit card?
Proving a statement about real numbers
How to resolve: Reviewer #1 says remove section X vs. Reviewer #2 says expand section X
What is this diamond of every day?
Recommendation letter by significant other if you worked with them professionally?
Are all players supposed to be able to see each others' character sheets?
MySQL importing CSV files really slow
Is this Paypal Github SDK reference really a dangerous site?
What is better: yes / no radio, or simple checkbox?
How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?
From an axiomatic set theoric approach why can we take uncountable unions?
Shifting between bemols and diesis in the key signature
Confusion about Complex Continued Fraction
What is the generally accepted pronunciation of “topoi”?
Django 2 Images from STATIC_URL is not loading in Css
2019 Community Moderator ElectionDoes Django scale?Django external css file problemcannot access static files in DjangoLink to a django static file doesnt workHow to link my css, js and image file link in djangoDjango : extract image from database and display in templateBest configuration for Django staticfilesLinking up CSS (and static files in general) to html in DjangoDisplay images that reside in a folder outside of django project folderDjango static file is not loading in my computer (windows 10) but its working on others computer (windows 10)
I'm working on a Django(2.1.7) project in which I need to load some images in css file.
Here's what I have so far:
From settings.py:
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/assets/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'assets'), ]
I have a directory in my main project folder named as assets and also have 'django.contrib.staticfiles' in INSTALLED_APPS and then I have mentioned some images in css as:
background: url('/assets/images/demo.png') center no-repeat;
The image is available in the images folder but not displaying in the template.
What can be wrong here?
python django django-2.0
|
show 1 more comment
I'm working on a Django(2.1.7) project in which I need to load some images in css file.
Here's what I have so far:
From settings.py:
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/assets/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'assets'), ]
I have a directory in my main project folder named as assets and also have 'django.contrib.staticfiles' in INSTALLED_APPS and then I have mentioned some images in css as:
background: url('/assets/images/demo.png') center no-repeat;
The image is available in the images folder but not displaying in the template.
What can be wrong here?
python django django-2.0
Did you specify% load static %at the beginning of your template?
– Rajan Sharma
Mar 6 at 14:30
the path you specify in your css is relative to your css file path. So this would only work if your css file is in a directory that contains the 'assets' directory.
– dirkgroten
Mar 6 at 14:31
Assuming you also have a /assets/css/ directory where your css file is located, the link to your image should be "../images/demo.png".
– dirkgroten
Mar 6 at 14:32
Hi @RajanSharma, I'm inside thecssfile where% load static %doesn't work and template is working.
– Abdul Rehman
Mar 6 at 14:32
Hi @dirkgroten I haveimagesfolder inside myassetsfolder`.
– Abdul Rehman
Mar 6 at 14:33
|
show 1 more comment
I'm working on a Django(2.1.7) project in which I need to load some images in css file.
Here's what I have so far:
From settings.py:
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/assets/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'assets'), ]
I have a directory in my main project folder named as assets and also have 'django.contrib.staticfiles' in INSTALLED_APPS and then I have mentioned some images in css as:
background: url('/assets/images/demo.png') center no-repeat;
The image is available in the images folder but not displaying in the template.
What can be wrong here?
python django django-2.0
I'm working on a Django(2.1.7) project in which I need to load some images in css file.
Here's what I have so far:
From settings.py:
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/assets/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'assets'), ]
I have a directory in my main project folder named as assets and also have 'django.contrib.staticfiles' in INSTALLED_APPS and then I have mentioned some images in css as:
background: url('/assets/images/demo.png') center no-repeat;
The image is available in the images folder but not displaying in the template.
What can be wrong here?
python django django-2.0
python django django-2.0
asked Mar 6 at 14:28
Abdul RehmanAbdul Rehman
1,061626
1,061626
Did you specify% load static %at the beginning of your template?
– Rajan Sharma
Mar 6 at 14:30
the path you specify in your css is relative to your css file path. So this would only work if your css file is in a directory that contains the 'assets' directory.
– dirkgroten
Mar 6 at 14:31
Assuming you also have a /assets/css/ directory where your css file is located, the link to your image should be "../images/demo.png".
– dirkgroten
Mar 6 at 14:32
Hi @RajanSharma, I'm inside thecssfile where% load static %doesn't work and template is working.
– Abdul Rehman
Mar 6 at 14:32
Hi @dirkgroten I haveimagesfolder inside myassetsfolder`.
– Abdul Rehman
Mar 6 at 14:33
|
show 1 more comment
Did you specify% load static %at the beginning of your template?
– Rajan Sharma
Mar 6 at 14:30
the path you specify in your css is relative to your css file path. So this would only work if your css file is in a directory that contains the 'assets' directory.
– dirkgroten
Mar 6 at 14:31
Assuming you also have a /assets/css/ directory where your css file is located, the link to your image should be "../images/demo.png".
– dirkgroten
Mar 6 at 14:32
Hi @RajanSharma, I'm inside thecssfile where% load static %doesn't work and template is working.
– Abdul Rehman
Mar 6 at 14:32
Hi @dirkgroten I haveimagesfolder inside myassetsfolder`.
– Abdul Rehman
Mar 6 at 14:33
Did you specify
% load static % at the beginning of your template?– Rajan Sharma
Mar 6 at 14:30
Did you specify
% load static % at the beginning of your template?– Rajan Sharma
Mar 6 at 14:30
the path you specify in your css is relative to your css file path. So this would only work if your css file is in a directory that contains the 'assets' directory.
– dirkgroten
Mar 6 at 14:31
the path you specify in your css is relative to your css file path. So this would only work if your css file is in a directory that contains the 'assets' directory.
– dirkgroten
Mar 6 at 14:31
Assuming you also have a /assets/css/ directory where your css file is located, the link to your image should be "../images/demo.png".
– dirkgroten
Mar 6 at 14:32
Assuming you also have a /assets/css/ directory where your css file is located, the link to your image should be "../images/demo.png".
– dirkgroten
Mar 6 at 14:32
Hi @RajanSharma, I'm inside the
css file where % load static % doesn't work and template is working.– Abdul Rehman
Mar 6 at 14:32
Hi @RajanSharma, I'm inside the
css file where % load static % doesn't work and template is working.– Abdul Rehman
Mar 6 at 14:32
Hi @dirkgroten I have
images folder inside my assets folder`.– Abdul Rehman
Mar 6 at 14:33
Hi @dirkgroten I have
images folder inside my assets folder`.– Abdul Rehman
Mar 6 at 14:33
|
show 1 more comment
2 Answers
2
active
oldest
votes
The path you specify in your css is relative to your css file path. So this url would only work if your css file is in a directory that contains the assets directory.
The question is where is your css file. Assuming it's in a /assets/css folder (inside assets), your url should be:
background: url('../images/demo.png') center no-repeat;
add a comment |
Add below snippet to your urls.py file
# <----------- rest of the code----------->
urlpatterns += static('/assets/', document_root=settings.STATIC_ROOT) + static(
settings.STATIC_URL, document_root=settings.STATIC_ROOT
)
1
This is not needed since the OP is using 'django.contrib.staticfiles' so in debug=True mode, runserver automatically finds the static files in the various /static directories of the apps and inside the /assets directory (since he added that to STATICFILES_DIRS). And even then, this should definitely be removed in production settings (so wrap inif settings.DEBUG == True:). And finally, it only serves the files if they're inSTATIC_ROOTso you'd have to runcollectstaticon your development machine all the time a change is made to static files.
– dirkgroten
Mar 6 at 15:03
add a comment |
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',
autoActivateHeartbeat: false,
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%2f55025449%2fdjango-2-images-from-static-url-is-not-loading-in-css%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The path you specify in your css is relative to your css file path. So this url would only work if your css file is in a directory that contains the assets directory.
The question is where is your css file. Assuming it's in a /assets/css folder (inside assets), your url should be:
background: url('../images/demo.png') center no-repeat;
add a comment |
The path you specify in your css is relative to your css file path. So this url would only work if your css file is in a directory that contains the assets directory.
The question is where is your css file. Assuming it's in a /assets/css folder (inside assets), your url should be:
background: url('../images/demo.png') center no-repeat;
add a comment |
The path you specify in your css is relative to your css file path. So this url would only work if your css file is in a directory that contains the assets directory.
The question is where is your css file. Assuming it's in a /assets/css folder (inside assets), your url should be:
background: url('../images/demo.png') center no-repeat;
The path you specify in your css is relative to your css file path. So this url would only work if your css file is in a directory that contains the assets directory.
The question is where is your css file. Assuming it's in a /assets/css folder (inside assets), your url should be:
background: url('../images/demo.png') center no-repeat;
answered Mar 6 at 14:33
dirkgrotendirkgroten
5,44611324
5,44611324
add a comment |
add a comment |
Add below snippet to your urls.py file
# <----------- rest of the code----------->
urlpatterns += static('/assets/', document_root=settings.STATIC_ROOT) + static(
settings.STATIC_URL, document_root=settings.STATIC_ROOT
)
1
This is not needed since the OP is using 'django.contrib.staticfiles' so in debug=True mode, runserver automatically finds the static files in the various /static directories of the apps and inside the /assets directory (since he added that to STATICFILES_DIRS). And even then, this should definitely be removed in production settings (so wrap inif settings.DEBUG == True:). And finally, it only serves the files if they're inSTATIC_ROOTso you'd have to runcollectstaticon your development machine all the time a change is made to static files.
– dirkgroten
Mar 6 at 15:03
add a comment |
Add below snippet to your urls.py file
# <----------- rest of the code----------->
urlpatterns += static('/assets/', document_root=settings.STATIC_ROOT) + static(
settings.STATIC_URL, document_root=settings.STATIC_ROOT
)
1
This is not needed since the OP is using 'django.contrib.staticfiles' so in debug=True mode, runserver automatically finds the static files in the various /static directories of the apps and inside the /assets directory (since he added that to STATICFILES_DIRS). And even then, this should definitely be removed in production settings (so wrap inif settings.DEBUG == True:). And finally, it only serves the files if they're inSTATIC_ROOTso you'd have to runcollectstaticon your development machine all the time a change is made to static files.
– dirkgroten
Mar 6 at 15:03
add a comment |
Add below snippet to your urls.py file
# <----------- rest of the code----------->
urlpatterns += static('/assets/', document_root=settings.STATIC_ROOT) + static(
settings.STATIC_URL, document_root=settings.STATIC_ROOT
)
Add below snippet to your urls.py file
# <----------- rest of the code----------->
urlpatterns += static('/assets/', document_root=settings.STATIC_ROOT) + static(
settings.STATIC_URL, document_root=settings.STATIC_ROOT
)
answered Mar 6 at 14:46
Devang PadhiyarDevang Padhiyar
406119
406119
1
This is not needed since the OP is using 'django.contrib.staticfiles' so in debug=True mode, runserver automatically finds the static files in the various /static directories of the apps and inside the /assets directory (since he added that to STATICFILES_DIRS). And even then, this should definitely be removed in production settings (so wrap inif settings.DEBUG == True:). And finally, it only serves the files if they're inSTATIC_ROOTso you'd have to runcollectstaticon your development machine all the time a change is made to static files.
– dirkgroten
Mar 6 at 15:03
add a comment |
1
This is not needed since the OP is using 'django.contrib.staticfiles' so in debug=True mode, runserver automatically finds the static files in the various /static directories of the apps and inside the /assets directory (since he added that to STATICFILES_DIRS). And even then, this should definitely be removed in production settings (so wrap inif settings.DEBUG == True:). And finally, it only serves the files if they're inSTATIC_ROOTso you'd have to runcollectstaticon your development machine all the time a change is made to static files.
– dirkgroten
Mar 6 at 15:03
1
1
This is not needed since the OP is using 'django.contrib.staticfiles' so in debug=True mode, runserver automatically finds the static files in the various /static directories of the apps and inside the /assets directory (since he added that to STATICFILES_DIRS). And even then, this should definitely be removed in production settings (so wrap in
if settings.DEBUG == True:). And finally, it only serves the files if they're in STATIC_ROOT so you'd have to run collectstatic on your development machine all the time a change is made to static files.– dirkgroten
Mar 6 at 15:03
This is not needed since the OP is using 'django.contrib.staticfiles' so in debug=True mode, runserver automatically finds the static files in the various /static directories of the apps and inside the /assets directory (since he added that to STATICFILES_DIRS). And even then, this should definitely be removed in production settings (so wrap in
if settings.DEBUG == True:). And finally, it only serves the files if they're in STATIC_ROOT so you'd have to run collectstatic on your development machine all the time a change is made to static files.– dirkgroten
Mar 6 at 15:03
add a comment |
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.
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%2f55025449%2fdjango-2-images-from-static-url-is-not-loading-in-css%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
Did you specify
% load static %at the beginning of your template?– Rajan Sharma
Mar 6 at 14:30
the path you specify in your css is relative to your css file path. So this would only work if your css file is in a directory that contains the 'assets' directory.
– dirkgroten
Mar 6 at 14:31
Assuming you also have a /assets/css/ directory where your css file is located, the link to your image should be "../images/demo.png".
– dirkgroten
Mar 6 at 14:32
Hi @RajanSharma, I'm inside the
cssfile where% load static %doesn't work and template is working.– Abdul Rehman
Mar 6 at 14:32
Hi @dirkgroten I have
imagesfolder inside myassetsfolder`.– Abdul Rehman
Mar 6 at 14:33