CSS file not Loading

36 views
Skip to first unread message

Suny

unread,
Jun 28, 2020, 9:07:22 AM6/28/20
to Django users
Do I need to add STATICFILES_DIRS in settings.py file

TREE STRUCTURE for reference :
.
├── db.sqlite3
├── Fotografie
│   ├── asgi.py
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-38.pyc
│   │   ├── settings.cpython-38.pyc
│   │   ├── urls.cpython-38.pyc
│   │   └── wsgi.cpython-38.pyc
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── Home
│   ├── admin.py
│   ├── apps.py
│   ├── __init__.py
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   ├── __init__.py
│   │   └── __pycache__
│   │       ├── 0001_initial.cpython-38.pyc
│   │       └── __init__.cpython-38.pyc
│   ├── models.py
│   ├── __pycache__
│   │   ├── admin.cpython-38.pyc
│   │   ├── apps.cpython-38.pyc
│   │   ├── __init__.cpython-38.pyc
│   │   ├── models.cpython-38.pyc
│   │   ├── urls.cpython-38.pyc
│   │   └── views.cpython-38.pyc
│   ├── static
│   │   └── Home
│   │       └── main.css
│   ├── templates
│   │   └── Home
│   │       ├── about.html
│   │       ├── base.html
│   │       ├── contact.html
│   │       └── home.html
│   ├── tests.py
│   ├── urls.py
│   └── views.py
├── manage.py
└── Users
    ├── admin.py
    ├── apps.py
    ├── __init__.py
    ├── migrations
    │   ├── __init__.py
    │   └── __pycache__
    │       └── __init__.cpython-38.pyc
    ├── models.py
    ├── __pycache__
    │   ├── admin.cpython-38.pyc
    │   ├── apps.cpython-38.pyc
    │   ├── __init__.cpython-38.pyc
    │   ├── models.cpython-38.pyc
    │   ├── urls.cpython-38.pyc
    │   └── views.cpython-38.pyc
    ├── templates
    │   └── Users
    │       └── register.html
    ├── tests.py
    ├── urls.py
    └── views.py


base.html file

{% load static %}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link rel="stylesheet" type="text/css" href="{% static 'Home/main.css' %}">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Sofia">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Annie Use Your Telescope">
    <link href='https://fonts.googleapis.com/css?family=Aclonica' rel='stylesheet'>
<title>Fotografie</title>

</head>

<body>
</body>


css file with main.css name

body {
  background-color: #181818;              /*background of page*/
  color: #FFFFFF;                   /*color of text*/
  margin-top: 1000rem;                /*margin from top*/
}

h1, h2, h3, h4, h5, h6 {
  color: #FFFFFF;
  text-transform: uppercase;
}

ul {
  margin: 0;
}


setting.py file
"""
Django settings for Fotografie project.

Generated by 'django-admin startproject' using Django 3.0.7.

For more information on this file, see

For the full list of settings and their values, see
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ')!e)l*b%z(ywdugroidcrjq4a%&dt7ha2*^amf8s150ndy%+@i'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [                                  #list collector
    'Home.apps.HomeConfig',
    'Users.apps.UsersConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'Fotografie.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'Fotografie.wsgi.application'


# Database

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)



STATIC_URL = '/static/'

















Clive Bruton

unread,
Jun 28, 2020, 9:58:44 AM6/28/20
to django...@googlegroups.com
If you are testing the site with manage.py runserver, then you have
to make sure debug is on. And you have to ensure the app knows where
the static directories are.


-- Clive
> <link rel="stylesheet" href="https://fonts.googleapis.com/css?
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to django-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/
> d/msgid/django-users/cd79beee-0e17-4ece-a876-0dd79d988d06o%
> 40googlegroups.com.

Ogunsanya Opeyemi

unread,
Jun 29, 2020, 4:59:21 AM6/29/20
to django...@googlegroups.com
Yes you need to add STATICFILES_DIRS.
OGUNSANYA OPEYEMI


Hadisur Rahman

unread,
Jun 29, 2020, 11:00:43 AM6/29/20
to django...@googlegroups.com

put this in your apps sittings on the below.

STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
STATIC_ROOT = os.path.join(BASE_DIR, 'assets')

And then run this code >> python manage.py collectstatic 
then >> python manage.py runserver


Mailtrack Sender notified by
Mailtrack 06/29/20, 08:58:27 PM

Suny

unread,
Jun 30, 2020, 1:59:36 AM6/30/20
to Django users
Thanks guys, 
Really appreciate your time and efforts for reviewing and responding back ...
I haven't made any changes to the code, looks like browser was taking the cache file of main.css and was taking a lot of time to update the file.
Just did hard refresh , and it worked .
Thanks again.

Reply all
Reply to author
Forward
0 new messages