Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The directory '/static/' in the STATICFILES_DIRS setting does not exist. (Visual Studio)

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')
like image 833
L K Avatar asked Nov 01 '25 21:11

L K


2 Answers

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.

like image 79
Emilio Billionario Avatar answered Nov 03 '25 11:11

Emilio Billionario


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

like image 33
Nerdy Ayubi Avatar answered Nov 03 '25 12:11

Nerdy Ayubi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!