首页 > 解决方案 > 部署应用程序时运行“$ python manage.py collectstatic --noinput”时出错

问题描述

Django 新手,尝试部署我的 Web 应用程序,但不断收到此错误。我确实了解追溯。任何帮助将不胜感激。

remote:        Traceback (most recent call last):
remote:          File "/tmp/build_3810ef0f/manage.py", line 22, in <module>
remote:            main()
remote:          File "/tmp/build_3810ef0f/manage.py", line 18, in main
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 375, in execute
remote:            self.fetch_command(subcommand).run_from_argv(self.argv)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 329, in run_from_argv
remote:            connections.close_all()
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/db/utils.py", line 225, in close_all
remote:            connection.close()
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 190, in close
remote:            if not self.is_in_memory_db():
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 280, in is_in_memory_db
remote:            return self.creation.is_in_memory_db(self.settings_dict['NAME'])
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/db/backends/sqlite3/creation.py", line 12, in is_in_memory_db
remote:            return database_name == ':memory:' or 'mode=memory' in database_name
remote:        TypeError: argument of type 'PosixPath' is not iterable
remote:
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.
remote:        See traceback above for details.
remote:
remote:        You may need to update application code to resolve this error.
remote:        Or, you can disable collectstatic for this application:
remote:
remote:           $ heroku config:set DISABLE_COLLECTSTATIC=1
remote:
remote:        https://devcenter.heroku.com/articles/django-assets
remote:  !     Push rejected, failed to compile Python app.

我的要求.txt

boto3==1.9.96
botocore==1.12.96
certifi==2018.10.15
chardet==3.0.4
dj-database-url==0.5.0
Django==2.1
django-crispy-forms==1.7.2
django-heroku==0.3.1
django-storages==1.7.1
docutils==0.14
gunicorn==19.9.0
idna==2.7
jmespath==0.9.3
Pillow==5.2.0
psycopg2-binary==2.9.1
python-dateutil==2.8.0
pytz==2018.5
requests==2.19.1
s3transfer==0.2.0
six==1.12.0
urllib3==1.23
whitenoise==4.1.2

我的 settings.py 文件

"""
Django settings for django_project1 project.

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/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


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-$+#gkkrq#w9(ewoanhj3^dq-4$li1p=%u6r^9tvr+obm-rey$k'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'users.apps.UsersConfig',
    'crispy_forms',
    'blog.apps.BlogConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

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


# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

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',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'



MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

CRISPY_TEMPLATE_PACK = 'bootstrap4'

我知道还有其他帖子有同样的问题,我已经尝试了所有的解决方案,但没有任何效果。我也遇到了 psycopg2 构建错误,但我通过用 psycopg2-binary 替换它来修复它。另外我不知道这是否相关,但我使用的是 conda virt env 并且 pip freeze > requirements.txt 返回几乎所有包,所以我使用了我一直关注的教程中的 requirements.txt 文件。这是 pip freeze 返回的部分内容。

Werkzeug @pycparser @ file:///tmp/build/80754af9/pycparser_1594388511720/work pycurl==7.43.0.6
pydocstyle @ file:///tmp/build/80754af9/pydocstyle_1616182067796/work
pyerfa @ file:///C:/ ci/pyerfa_1619391071834/work
pyflakes@file:///home/ktietz/src/ci_ipy2/pyflakes_1612551159640/work
Pygments@file:///tmp/build/80754af9/pygments_1615143339740/work

标签: pythondjango

解决方案


推荐阅读