4

When I want to "python manage.py makemigrations", it returns the following.

System check identified some issues:

WARNINGS
?: (staticfiles.W004) The directory '/static/' in the STATICFILES_DIRS setting does not exist.

How should I solve this issue?

from pathlib import Path import os  BASE_DIR = Path(__file__).resolve().parent.parent  ALLOWED_HOSTS = ['*']  INSTALLED_APPS = [     'django.contrib.admin',     'django.contrib.auth',     'django.contrib.contenttypes',     'django.contrib.sessions',     'django.contrib.messages',     'django.contrib.staticfiles',      'products',     'orders', ]

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 = ‘rtu_server.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 = ‘rtu_server.wsgi.application'

DATABASES = {     'default': {         'ENGINE': 'django.db.backends.sqlite3',         'NAME': BASE_DIR / 'db.sqlite3',     } }  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',     }, ] 

LANGUAGE_CODE = 'en-us'  TIME_ZONE = 'Asia/Hong_Kong'  USE_I18N = True  USE_TZ = True   STATIC_URL = 'static/'  STATICFILES_DIRS = [     os.path.join(BASE_DIR, 'static') ]  DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'  MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
L K
  • 49
  • 1
  • 1
  • 2

3 Answers3

9

It just says that you created STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")] in your settings.py, but you didn't have any static folder in your project.

It is not a big issue right now because you might not be using external CSS or JS. But if you want to solve the issue, you can just create a static folder in your project.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
2

Create a folder "static" in root directory if you still see error, then.

The problem is with this i believe,

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

Let's say this is tree of folder where your "settings.py" is:

E:\\Project>Project>mySettings>settings.py

Then you have to modify BASE_DIR little bit like below,

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

one .parent for each folder

Nerdy Ayubi
  • 70
  • 1
  • 7
1

So what you need to do here to make it easier for you is to navigate to the location where you have your project created and create a FOLDER called static. Don't try to do it for your IDE editor as you might end up getting confused. I am assuming you are trying to link up files such as CSS to your Django project. Do this and your problem will be solved.

Also, remember to load your static statement at the header of your HTML page.

As an example:

<link rel='stylesheet' href='{% static 'style.css' %}' type='text/css'>
{% load static %}
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Adeniyi
  • 21
  • 1