Static Files won't show with Django
<!DOCTYPE html>
{% load staticfiles %}
<html>
........
<img src="{% static 'images/parralax/spaces.jpg' %}" width = 250px />
<body>
Above code won't show the image I have as a background. Really unsure how to fix this issue.
Here are my setting files. I think the issue is coming from linking to CSS not working.
Thanks in advance!
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')
STATIC_DIR = os.path.join(BASE_DIR, 'static')
MEDIA_DIR = os.path.join(BASE_DIR,'media')
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR,],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [.....
],
},
},
]
STATICFILES_DIRS = [STATIC_DIR, ]
STATIC_URL = '/static/'
MEDIA_ROOT = MEDIA_DIR #where to look for files
MEDIA_URL = '/media/' #where to serve files from on url
WSGI_APPLICATION = 'Space.wsgi.application'
STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')
.....
.....
urls.py
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^Spaces/', include('Spaces.urls')),
#Django Admin
path('admin/', admin.site.urls),
#User Management
url(r'^accounts/', include('allauth.urls')),
path(r'^users/', include('users.urls')),
path(r'^users/', include('django.contrib.auth.urls')),
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_DIR)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_DIR)
Please help :)
Cheers!
css django
add a comment |
<!DOCTYPE html>
{% load staticfiles %}
<html>
........
<img src="{% static 'images/parralax/spaces.jpg' %}" width = 250px />
<body>
Above code won't show the image I have as a background. Really unsure how to fix this issue.
Here are my setting files. I think the issue is coming from linking to CSS not working.
Thanks in advance!
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')
STATIC_DIR = os.path.join(BASE_DIR, 'static')
MEDIA_DIR = os.path.join(BASE_DIR,'media')
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR,],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [.....
],
},
},
]
STATICFILES_DIRS = [STATIC_DIR, ]
STATIC_URL = '/static/'
MEDIA_ROOT = MEDIA_DIR #where to look for files
MEDIA_URL = '/media/' #where to serve files from on url
WSGI_APPLICATION = 'Space.wsgi.application'
STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')
.....
.....
urls.py
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^Spaces/', include('Spaces.urls')),
#Django Admin
path('admin/', admin.site.urls),
#User Management
url(r'^accounts/', include('allauth.urls')),
path(r'^users/', include('users.urls')),
path(r'^users/', include('django.contrib.auth.urls')),
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_DIR)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_DIR)
Please help :)
Cheers!
css django
{% static 'images/parallax/home/9.jpg' %}
what url does it produce? Which response do you get when opening this url?
– Ivan Starostin
Nov 20 '18 at 10:46
Page not found (404) Request URL: 127.0.0.1:8000/Spaces/images/parallax/home/9.jpg
– Michael Holborn
Nov 22 '18 at 3:40
What are STATICFILES_DIRS, STATIC_URL values? Did you runcollectstatic
?
– Ivan Starostin
Nov 22 '18 at 9:21
Given config would result in127.0.0.1:8000/static/images/parallax/home/9.jpg
because ofstatic
function usage andSTATIC_URL = '/static/'
value. And I assume you did not runcollectstatic
and you're trying to reach image located insideSpaces
app subfolders. Is this correct?
– Ivan Starostin
Nov 23 '18 at 14:06
Are you running withDEBUG = True
orDEBUG = False
?
– ivissani
Nov 29 '18 at 16:59
add a comment |
<!DOCTYPE html>
{% load staticfiles %}
<html>
........
<img src="{% static 'images/parralax/spaces.jpg' %}" width = 250px />
<body>
Above code won't show the image I have as a background. Really unsure how to fix this issue.
Here are my setting files. I think the issue is coming from linking to CSS not working.
Thanks in advance!
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')
STATIC_DIR = os.path.join(BASE_DIR, 'static')
MEDIA_DIR = os.path.join(BASE_DIR,'media')
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR,],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [.....
],
},
},
]
STATICFILES_DIRS = [STATIC_DIR, ]
STATIC_URL = '/static/'
MEDIA_ROOT = MEDIA_DIR #where to look for files
MEDIA_URL = '/media/' #where to serve files from on url
WSGI_APPLICATION = 'Space.wsgi.application'
STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')
.....
.....
urls.py
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^Spaces/', include('Spaces.urls')),
#Django Admin
path('admin/', admin.site.urls),
#User Management
url(r'^accounts/', include('allauth.urls')),
path(r'^users/', include('users.urls')),
path(r'^users/', include('django.contrib.auth.urls')),
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_DIR)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_DIR)
Please help :)
Cheers!
css django
<!DOCTYPE html>
{% load staticfiles %}
<html>
........
<img src="{% static 'images/parralax/spaces.jpg' %}" width = 250px />
<body>
Above code won't show the image I have as a background. Really unsure how to fix this issue.
Here are my setting files. I think the issue is coming from linking to CSS not working.
Thanks in advance!
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')
STATIC_DIR = os.path.join(BASE_DIR, 'static')
MEDIA_DIR = os.path.join(BASE_DIR,'media')
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR,],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [.....
],
},
},
]
STATICFILES_DIRS = [STATIC_DIR, ]
STATIC_URL = '/static/'
MEDIA_ROOT = MEDIA_DIR #where to look for files
MEDIA_URL = '/media/' #where to serve files from on url
WSGI_APPLICATION = 'Space.wsgi.application'
STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')
.....
.....
urls.py
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^Spaces/', include('Spaces.urls')),
#Django Admin
path('admin/', admin.site.urls),
#User Management
url(r'^accounts/', include('allauth.urls')),
path(r'^users/', include('users.urls')),
path(r'^users/', include('django.contrib.auth.urls')),
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_DIR)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_DIR)
Please help :)
Cheers!
css django
css django
edited Nov 23 '18 at 3:37
Michael Holborn
asked Nov 20 '18 at 10:34
Michael HolbornMichael Holborn
98216
98216
{% static 'images/parallax/home/9.jpg' %}
what url does it produce? Which response do you get when opening this url?
– Ivan Starostin
Nov 20 '18 at 10:46
Page not found (404) Request URL: 127.0.0.1:8000/Spaces/images/parallax/home/9.jpg
– Michael Holborn
Nov 22 '18 at 3:40
What are STATICFILES_DIRS, STATIC_URL values? Did you runcollectstatic
?
– Ivan Starostin
Nov 22 '18 at 9:21
Given config would result in127.0.0.1:8000/static/images/parallax/home/9.jpg
because ofstatic
function usage andSTATIC_URL = '/static/'
value. And I assume you did not runcollectstatic
and you're trying to reach image located insideSpaces
app subfolders. Is this correct?
– Ivan Starostin
Nov 23 '18 at 14:06
Are you running withDEBUG = True
orDEBUG = False
?
– ivissani
Nov 29 '18 at 16:59
add a comment |
{% static 'images/parallax/home/9.jpg' %}
what url does it produce? Which response do you get when opening this url?
– Ivan Starostin
Nov 20 '18 at 10:46
Page not found (404) Request URL: 127.0.0.1:8000/Spaces/images/parallax/home/9.jpg
– Michael Holborn
Nov 22 '18 at 3:40
What are STATICFILES_DIRS, STATIC_URL values? Did you runcollectstatic
?
– Ivan Starostin
Nov 22 '18 at 9:21
Given config would result in127.0.0.1:8000/static/images/parallax/home/9.jpg
because ofstatic
function usage andSTATIC_URL = '/static/'
value. And I assume you did not runcollectstatic
and you're trying to reach image located insideSpaces
app subfolders. Is this correct?
– Ivan Starostin
Nov 23 '18 at 14:06
Are you running withDEBUG = True
orDEBUG = False
?
– ivissani
Nov 29 '18 at 16:59
{% static 'images/parallax/home/9.jpg' %}
what url does it produce? Which response do you get when opening this url?– Ivan Starostin
Nov 20 '18 at 10:46
{% static 'images/parallax/home/9.jpg' %}
what url does it produce? Which response do you get when opening this url?– Ivan Starostin
Nov 20 '18 at 10:46
Page not found (404) Request URL: 127.0.0.1:8000/Spaces/images/parallax/home/9.jpg
– Michael Holborn
Nov 22 '18 at 3:40
Page not found (404) Request URL: 127.0.0.1:8000/Spaces/images/parallax/home/9.jpg
– Michael Holborn
Nov 22 '18 at 3:40
What are STATICFILES_DIRS, STATIC_URL values? Did you run
collectstatic
?– Ivan Starostin
Nov 22 '18 at 9:21
What are STATICFILES_DIRS, STATIC_URL values? Did you run
collectstatic
?– Ivan Starostin
Nov 22 '18 at 9:21
Given config would result in
127.0.0.1:8000/static/images/parallax/home/9.jpg
because of static
function usage and STATIC_URL = '/static/'
value. And I assume you did not run collectstatic
and you're trying to reach image located inside Spaces
app subfolders. Is this correct?– Ivan Starostin
Nov 23 '18 at 14:06
Given config would result in
127.0.0.1:8000/static/images/parallax/home/9.jpg
because of static
function usage and STATIC_URL = '/static/'
value. And I assume you did not run collectstatic
and you're trying to reach image located inside Spaces
app subfolders. Is this correct?– Ivan Starostin
Nov 23 '18 at 14:06
Are you running with
DEBUG = True
or DEBUG = False
?– ivissani
Nov 29 '18 at 16:59
Are you running with
DEBUG = True
or DEBUG = False
?– ivissani
Nov 29 '18 at 16:59
add a comment |
4 Answers
4
active
oldest
votes
Be sure you write this line top of your html file:
{% load static %}
second point is close your div with :
</div>
and write something into div or provide a 'height' attribute for your dive:
<div class="full-screen force-full-screen" style="background: url('{% static 'images/parallax/home/9.jpg' %}') center center no-repeat; background-size: cover;height: 100px;">
third point : be sure this two line is in your settings.py:
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_URL = '/static/'
Hope this helps.
add a comment |
use
{% load static from staticfiles %}
add a comment |
Use {% load static %}
at the start of your HTML files(except for base.html
) instead of {% load staticfiles %}
.
And make sure this is available in your settings.py
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_URL = '/static/'
add a comment |
I fixed this issue.
I was linking the wrong folder the entire time. Silly mistake.
Thanks everyone for your help :)
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%2f53391075%2fstatic-files-wont-show-with-django%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Be sure you write this line top of your html file:
{% load static %}
second point is close your div with :
</div>
and write something into div or provide a 'height' attribute for your dive:
<div class="full-screen force-full-screen" style="background: url('{% static 'images/parallax/home/9.jpg' %}') center center no-repeat; background-size: cover;height: 100px;">
third point : be sure this two line is in your settings.py:
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_URL = '/static/'
Hope this helps.
add a comment |
Be sure you write this line top of your html file:
{% load static %}
second point is close your div with :
</div>
and write something into div or provide a 'height' attribute for your dive:
<div class="full-screen force-full-screen" style="background: url('{% static 'images/parallax/home/9.jpg' %}') center center no-repeat; background-size: cover;height: 100px;">
third point : be sure this two line is in your settings.py:
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_URL = '/static/'
Hope this helps.
add a comment |
Be sure you write this line top of your html file:
{% load static %}
second point is close your div with :
</div>
and write something into div or provide a 'height' attribute for your dive:
<div class="full-screen force-full-screen" style="background: url('{% static 'images/parallax/home/9.jpg' %}') center center no-repeat; background-size: cover;height: 100px;">
third point : be sure this two line is in your settings.py:
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_URL = '/static/'
Hope this helps.
Be sure you write this line top of your html file:
{% load static %}
second point is close your div with :
</div>
and write something into div or provide a 'height' attribute for your dive:
<div class="full-screen force-full-screen" style="background: url('{% static 'images/parallax/home/9.jpg' %}') center center no-repeat; background-size: cover;height: 100px;">
third point : be sure this two line is in your settings.py:
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_URL = '/static/'
Hope this helps.
answered Nov 20 '18 at 10:54
Mohammad HasaniMohammad Hasani
235
235
add a comment |
add a comment |
use
{% load static from staticfiles %}
add a comment |
use
{% load static from staticfiles %}
add a comment |
use
{% load static from staticfiles %}
use
{% load static from staticfiles %}
answered Nov 26 '18 at 12:16
subramanyamsubramanyam
514
514
add a comment |
add a comment |
Use {% load static %}
at the start of your HTML files(except for base.html
) instead of {% load staticfiles %}
.
And make sure this is available in your settings.py
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_URL = '/static/'
add a comment |
Use {% load static %}
at the start of your HTML files(except for base.html
) instead of {% load staticfiles %}
.
And make sure this is available in your settings.py
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_URL = '/static/'
add a comment |
Use {% load static %}
at the start of your HTML files(except for base.html
) instead of {% load staticfiles %}
.
And make sure this is available in your settings.py
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_URL = '/static/'
Use {% load static %}
at the start of your HTML files(except for base.html
) instead of {% load staticfiles %}
.
And make sure this is available in your settings.py
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_URL = '/static/'
answered Nov 28 '18 at 6:48
ChaiVanChaiVan
214
214
add a comment |
add a comment |
I fixed this issue.
I was linking the wrong folder the entire time. Silly mistake.
Thanks everyone for your help :)
add a comment |
I fixed this issue.
I was linking the wrong folder the entire time. Silly mistake.
Thanks everyone for your help :)
add a comment |
I fixed this issue.
I was linking the wrong folder the entire time. Silly mistake.
Thanks everyone for your help :)
I fixed this issue.
I was linking the wrong folder the entire time. Silly mistake.
Thanks everyone for your help :)
answered Dec 11 '18 at 3:47
Michael HolbornMichael Holborn
98216
98216
add a comment |
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%2f53391075%2fstatic-files-wont-show-with-django%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
{% static 'images/parallax/home/9.jpg' %}
what url does it produce? Which response do you get when opening this url?– Ivan Starostin
Nov 20 '18 at 10:46
Page not found (404) Request URL: 127.0.0.1:8000/Spaces/images/parallax/home/9.jpg
– Michael Holborn
Nov 22 '18 at 3:40
What are STATICFILES_DIRS, STATIC_URL values? Did you run
collectstatic
?– Ivan Starostin
Nov 22 '18 at 9:21
Given config would result in
127.0.0.1:8000/static/images/parallax/home/9.jpg
because ofstatic
function usage andSTATIC_URL = '/static/'
value. And I assume you did not runcollectstatic
and you're trying to reach image located insideSpaces
app subfolders. Is this correct?– Ivan Starostin
Nov 23 '18 at 14:06
Are you running with
DEBUG = True
orDEBUG = False
?– ivissani
Nov 29 '18 at 16:59