Reputation: 139
ValueError: not enough values to unpack (expected 2, got 1) how can I solve this problem I am just tried to get this Error for a long now also I have added my settings file please look after this couldn't understand where this problem is hidden I need your help sir please help me out
This is The Error
(myDjangoEnv) D:\Django\User\learning_users>python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\ABC\.conda\envs\myDjangoEnv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\ABC\.conda\envs\myDjangoEnv\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\ABC\.conda\envs\myDjangoEnv\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\ABC\.conda\envs\myDjangoEnv\lib\site-packages\django\core\management\base.py", line 366, in execute
self.check()
File "C:\Users\ABC\.conda\envs\myDjangoEnv\lib\site-packages\django\core\management\base.py", line 392, in check
all_issues = self._run_checks(
File "C:\Users\ABC\.conda\envs\myDjangoEnv\lib\site-packages\django\core\management\commands\migrate.py", line 64, in _run_checks
issues.extend(super()._run_checks(**kwargs))
File "C:\Users\ABC\.conda\envs\myDjangoEnv\lib\site-packages\django\core\management\base.py", line 382, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\ABC\.conda\envs\myDjangoEnv\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\ABC\.conda\envs\myDjangoEnv\lib\site-packages\django\contrib\staticfiles\checks.py", line 7, in check_finders
for finder in get_finders():
File "C:\Users\ABC\.conda\envs\myDjangoEnv\lib\site-packages\django\contrib\staticfiles\finders.py", line 282, in get_finders
yield get_finder(finder_path)
File "C:\Users\ABC\.conda\envs\myDjangoEnv\lib\site-packages\django\contrib\staticfiles\finders.py", line 295, in get_finder
return Finder()
File "C:\Users\ABC\.conda\envs\myDjangoEnv\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)
models.py
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class UserProfileInfo(models.Model):
# user = models.OneToOneField(User)
user = models.OneToOneField(User, on_delete=models.CASCADE)
# user = models.ForeignKey(User,models.SET_NULL,blank=True,null=True)
# user = models.ForeignKey(User, on_delete=models.PROTECT)
#additional
profile_site = models.URLField(blank = True)
profile_pic = models.ImageField(upload_to='profile_pics', blank=True)
def __str__(self):
return self.user.username
forms.py
from django import forms
from django.contrib.auth.models import User
from basic_app.models import UserProfileInfo
class UserForm(forms.ModelForm):
password = forms.CharField(widget = forms.PasswordInput())
class meta():
model = User
fields = ('username', 'email', 'password')
class UserProfileInfoForm(forms.ModelForm):
class meta():
model = UserProfileInfo
fields = ('profile_site', 'profile_pic')
views.py
from django.shortcuts import render
from basic_app.forms import UserForm, UserProfileInfoForm
# Create your views here.
def index(request):
return render(request, 'basic_app/index.html')
def register(request):
registered = False
if request.method = 'POST':
user_form = UserForm(data = request.POST)
profile_form = UserProfileInfoForm(data = request.POST)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
user.set_password(user.password)
user.save()
profile = profile_form.save(commit = False)
profile.user = user
if 'profile_pic' in request.FILES:
profile.profile_pic = request.FILES['profile_pic']
profile.save()
registered = True
else:
print(user_form.errors, profile_form.errors)
else:
user_form = UserForm()
profile_form = UserProfileInfoForm()
return render(request, 'basic_app/registration.html',
{'user_form':user_form,
'profile_form':profile_form,
'registered':registered})
settings.py
"""
Django settings for learning_users project.
Generated by 'django-admin startproject' using Django 3.0.3.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""
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__)))
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')
STATIC_DIR = os.path.join(BASE_DIR, 'static')
MEDIA_DIR = os.path.join(BASE_DIR, 'media')
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '!v@!p=si_24u(h6j49y1@_)0uex$+#aye_r36p#51m23#inr-f'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'basic_app',
]
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 = 'learning_users.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR],
'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 = 'learning_users.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
PASSWORD_HASHERS = [
'django.contrib.auth.hashers.Argon2PasswordHasher',
'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
'django.contrib.auth.hashers.BCryptPasswordHasher',
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
]
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
'OPTION': {'min_length':9}
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [STATIC_DIR],
#MEDIA
MEDIA_ROOT = MEDIA_DIR
MEDIA_URL = '/media/'
Upvotes: 1
Views: 3021
Reputation: 1586
You have a trailing comma on this line
STATICFILES_DIRS = [STATIC_DIR],
^
It makes STATICFILES_DIRS a list of tuples instead of a list of strings.
Delete that comma. Pls, let me know if it helps.
Also perhaps this might help as well
Upvotes: 3