I know this question has been asked many times and I have seen all the answers given, but none of them worked for me. I am a newbie and trying to get access to CSS files in my Django template but it is not working, I have tried many options but none of them worked for me. Here I am using Django 2.2 in my project. Can you please help me to find out the mistake?
settings.py
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/
STATIC_URL = '/static/'
MEDIA_URL = '/images/'
STAICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
MEDIA_ROOT = os.path.join(BASE_DIR, 'static/images')
urls.py
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include
urlpatterns = []
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('GalaxyOffset.urls')),
]
basic.css
body{
background: url('{% static "../images/photo1.jpg" %}') no-repeat center center fixed;
-webkit-background-size: cover;
-moj-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-color: #f5fbff;
}
basic.html
<!doctype html>
<html lang="en">
<head>
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static '/css/basic.css' %}">
<title>{% block title%} {% endblock %} | Galaxy Offset</title>
</head>
<body>
<div class="container">
<h1>Welcome to the first page </h1>
{% block body %} {% endblock %}
</div>
</body>
</html>
project hierarchy This is my Project hierarchy
Here I want to access my CSS file but I couldn't. Can you please help me to figure out what am I doing wrong or missing here?