ValueError: not enough values to unpack (expected 2, got 1) in Django Framework

Viewed 1629

I am beginner in django, I just starts learning how to load static files and all about static file. After setting whole code when I run the server I encounter with this error:

`C:\Users\Lenovo\Documents\Django project\project3\fees\views.py changed, reloading.
Watching for file changes with StatReloader
Performing system checks...

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Users\Lenovo\anaconda3\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\Lenovo\anaconda3\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Lenovo\anaconda3\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\Lenovo\anaconda3\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run
    self.check(display_num_errors=True)
  File "C:\Users\Lenovo\anaconda3\lib\site-packages\django\core\management\base.py", line 392, in check
    all_issues = checks.run_checks(
  File "C:\Users\Lenovo\anaconda3\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "C:\Users\Lenovo\anaconda3\lib\site-packages\django\contrib\staticfiles\checks.py", line 7, in check_finders
    for finder in get_finders():
  File "C:\Users\Lenovo\anaconda3\lib\site-packages\django\contrib\staticfiles\finders.py", line 282, in get_finders
    yield get_finder(finder_path)
  File "C:\Users\Lenovo\anaconda3\lib\site-packages\django\contrib\staticfiles\finders.py", line 295, in get_finder
    return Finder()
  File "C:\Users\Lenovo\anaconda3\lib\site-packages\django\contrib\staticfiles\finders.py", line 59, in __init__
    prefix, root = root
ValueError: not enough values to unpack (expected 2, got 1)`

please tell me why I am getting this error and how can i solve it.

Here is setting.py files

"""
Django settings for project3 project.

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

For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""

from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
TEMPLATE_DIRS = [os.path.join(BASE_DIR / 'templates'),]
STATIC_DIRS = [os.path.join(BASE_DIR / 'static'),]

# Application definition

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


TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': TEMPLATE_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',
            ],
        },
    },
]



# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = [STATIC_DIRS,]
2 Answers

Django 3.1 does not use os to join paths in settings.py any more. It uses pathlib, which gives a Path object ...

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

This can then be joined with a slash only:

TEMPLATE_DIRS = [BASE_DIR / 'templates',]
STATIC_DIRS = [BASE_DIR / 'static',]

No need to import os at all then ...

I susepct what is happening is that the code in finders.py is expecting the 2 parts of a pathlib join using /, and you're then combining that somehow using os.join, which is reducing it to one var, hence the missing value. This last bit is kind of guesswork though - I've not tested that's exactly what's going on. But fix your code as I suggest and I think it will work.

This is how I am configuring things in my current project in 3.1

TEMPLATE_DIR = BASE_DIR / "templates"
TEMPLATES = [
{
    "BACKEND": "django.template.backends.django.DjangoTemplates",
    "DIRS": [
        TEMPLATE_DIR,
    ],
    ...
}

...

STATIC_URL = "/static/"
STATICFILES_DIRS = (BASE_DIR / "static",)
prefix, root = root

change it to

prefix = root

or

    prefix, root = root, root
Related