Reputation: 1016
<!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!
Upvotes: 4
Views: 703
Reputation: 1016
I fixed this issue.
I was linking the wrong folder the entire time. Silly mistake.
Thanks everyone for your help :)
Upvotes: 0
Reputation: 131
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/'
Upvotes: 1
Reputation: 33
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.
Upvotes: 3