首页 > 解决方案 > ValueError: no enough values to unpack (expected 2, got 1) 我怎么能解决这个问题我刚刚试过

问题描述

ValueError: no enough values to unpack (expected 2, got 1) 我该如何解决这个问题我只是想得到这个错误很长时间了我也添加了我的设置文件请看这个不明白这个问题在哪里被隐藏了我需要你的帮助先生请帮帮我

这是错误

(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)

模型.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

表格.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')

视图.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})

设置.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/'

标签: pythondjangopython-3.x

解决方案


您在此行有一个尾随逗号

STATICFILES_DIRS    = [STATIC_DIR],
                                  ^                                 

它使 STATICFILES_DIRS 成为元组列表而不是字符串列表。

删除那个逗号。请让我知道它是否有帮助。

也许这也可能有帮助


推荐阅读