0

Im getting this error "GET /static/bootstrap.min.css.css HTTP/1.1" 404 68 in my terminal whenever I update my page with prod.py I build. I think it's my code in my settings.py that is wrong and with the static files also.

there are my codes

1. B_F1                #project name
  2-1. B_F1
      3. settings
        4-1. base.py
        4-2. dev.py
        4-3. prod.py   # i use it when i publish 
  2-2. B_F_user        # app name
  2-3. static
      3. bootstrap.min.css

this is base.py code

from pathlib import Path
import os
import json
from django.core.exceptions import ImproperlyConfigured

BASE_DIR = Path(__file__).resolve().parent.parent.parent

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

'B_F_user',

]
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 = 'B_F1.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',
            ],
        },
    },
]

and this is prod.py code

from .base import *

DEBUG = False

DATABASES = {
    'default': {
    'ENGINE': 'django.db.backends.sqlite3',
    'NAME': BASE_DIR / 'db.sqlite3',
    }
}

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

and it my base.html

<!DOCTYPE html>
<html>
{% load static %}

<head>
    <meta charset="utf-8">
    <meta name = "viewport" content = "width=device-width, initial-scale=1">    
    <link rel="stylesheet" href="/static/bootstrap.min.css"/>

i used manage.py collectstaic but it's still not working with this address

You have requested to collect static files at the destination
location as specified in your settings:

    /Users/sungsmacpro/tmp/B_F_non_session/B_F1/static

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes

what should i fix it?

newbieeee
  • 1
  • 1
  • 2
  • From what I know from using express, usually the static folder is checked if you don't have a dynamic path that matches a request. For example, if you did `GET /static/style.ccss` and have the static path set to /public, express will first check if you have a matching dynamic path, and then check if there exists a file `./public/static/style.css`. Maybe that's how django works as well? So in other words try setting href to `/bootstrap.min.css` instead of `static/bootstrap.min.css`. – Real Awesomeness Jan 18 '21 at 01:51
  • Also, do you use `STATIC_URL` anywhere? – Real Awesomeness Jan 18 '21 at 01:54
  • @RealAwesomeness thx to reply. i do `/bootstrap.min.css` it's not working :( and i use `STATIC_URL = '/static/'` – newbieeee Jan 18 '21 at 02:21
  • @RealAwesomeness i try to print the path : `STATIC_ROOT` and the result is `/Users/sungsmacpro/tmp/B_F_non_session/B_F1/static` it's same with static files destination location. :( – newbieeee Jan 18 '21 at 02:23
  • 2
    when i change the settings `DEBUG = True` & `STATIC_URL = '/static/'` `STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static'),] ` it works very well.... – newbieeee Jan 18 '21 at 02:28

0 Answers0