【问题标题】:how to solve Heroku cllect static --noiput error如何解决 Heroku cllect static --noiput 错误
【发布时间】:2021-06-02 06:46:40
【问题描述】:

当我在 Heroku 上部署我的网络应用程序时,它给了我一个错误,下面是我的日志文件 我为学习目的创建了这个应用程序,现在我想部署这个 Django 应用程序,但在部署时遇到了一些错误,我按照 youtube 上的教程进行操作,但我无法解决这个问题。

-----> Building on the Heroku-20 stack
-----> Python app detected
 !     Python has released a security update! Please consider upgrading to python-3.9.2
       Learn More: https://devcenter.heroku.com/articles/python-runtimes
-----> Installing python-3.9.1
-----> Installing pip 20.1.1, setuptools 47.1.1 and wheel 0.34.2
-----> Installing SQLite3
-----> Installing requirements with pip
       Collecting asgiref==3.3.1
         Downloading asgiref-3.3.1-py3-none-any.whl (19 kB)
       Collecting certifi==2020.12.5
         Downloading certifi-2020.12.5-py2.py3-none-any.whl (147 kB)
       Collecting chardet==4.0.0
         Downloading chardet-4.0.0-py2.py3-none-any.whl (178 kB)
       Collecting Django==3.1.4
         Downloading Django-3.1.4-py3-none-any.whl (7.8 MB)
       Collecting gunicorn==20.0.4
         Downloading gunicorn-20.0.4-py2.py3-none-any.whl (77 kB)
       Collecting idna==2.10
         Downloading idna-2.10-py2.py3-none-any.whl (58 kB)
       Collecting pycryptodome==3.9.9
         Downloading pycryptodome-3.9.9-cp39-cp39-manylinux1_x86_64.whl (13.7 MB)
       Collecting pytz==2020.5
         Downloading pytz-2020.5-py2.py3-none-any.whl (510 kB)
       Collecting razorpay==1.2.0
         Downloading razorpay-1.2.0-py3-none-any.whl (162 kB)
       Collecting requests==2.25.1
         Downloading requests-2.25.1-py2.py3-none-any.whl (61 kB)
       Collecting sqlparse==0.4.1
         Downloading sqlparse-0.4.1-py3-none-any.whl (42 kB)
       Collecting urllib3==1.26.2
         Downloading urllib3-1.26.2-py2.py3-none-any.whl (136 kB)
       Collecting whitenoise==5.2.0
         Downloading whitenoise-5.2.0-py2.py3-none-any.whl (19 kB)
       Installing collected packages: asgiref, certifi, chardet, sqlparse, pytz, Django, gunicorn, idna, pycryptodome, urllib3, requests, razorpay, whitenoise
       Successfully installed Django-3.1.4 asgiref-3.3.1 certifi-2020.12.5 chardet-4.0.0 gunicorn-20.0.4 idna-2.10 pycryptodome-3.9.9 pytz-2020.5 razorpay-1.2.0 requests-2.25.1 sqlparse-0.4.1 urllib3-1.26.2 whitenoise-5.2.0
-----> $ python manage.py collectstatic --noinput
       Traceback (most recent call last):
         File "/tmp/build_ccba9798_/manage.py", line 22, in <module>
           main()
         File "/tmp/build_ccba9798_/manage.py", line 18, in main
           execute_from_command_line(sys.argv)
         File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
           utility.execute()
         File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
           self.fetch_command(subcommand).run_from_argv(self.argv)
         File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 330, in run_from_argv
           self.execute(*args, **cmd_options)
         File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 371, in execute
           output = self.handle(*args, **options)
         File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 194, in handle
           collected = self.collect()
         File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 109, in collect
           for path, storage in finder.list(self.ignore_patterns):
         File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/finders.py", line 130, in list
           for path in utils.get_files(storage, ignore_patterns):
         File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/utils.py", line 23, in get_files
           directories, files = storage.listdir(location)
         File "/app/.heroku/python/lib/python3.9/site-packages/django/core/files/storage.py", line 316, in listdir
           for entry in os.scandir(path):
       FileNotFoundError: [Errno 2] No such file or directory: '/tmp/build_ccba9798_/static'
 !     Error while running '$ python manage.py collectstatic --noinput'.
       See traceback above for details.
       You may need to update application code to resolve this error.
       Or, you can disable collectstatic for this application:
          $ heroku config:set DISABLE_COLLECTSTATIC=1
       https://devcenter.heroku.com/articles/django-assets
 !     Push rejected, failed to compile Python app.
 !     Push failed

Setting.py

from pathlib import Path

# 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.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'g3@+#nwg2t6d*4a57!z-jo)@%80icu5xs6&enxs*k(2s&d2qxn'

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

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
    'home.apps.HomeConfig',
    'index.apps.IndexConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    '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 = 'scc.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 = 'scc.wsgi.application'


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

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


# Password validation
# https://docs.djangoproject.com/en/3.1/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.1/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.1/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = [
    BASE_DIR / "static",
    '/static/',
]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

这是我的 manage.py 文件

#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'scc.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

请大家帮忙,我现在该怎么办It is my git repo

【问题讨论】:

    标签: python django heroku deployment web-deployment


    【解决方案1】:

    STATICFILES_DIRS 用于指定附加目录以在运行时查找静态文件

    python manage.py collectstatic.

    默认情况下,当您运行此命令时,它会在您安装的每个应用程序中搜索 static 目录。

    您得到的错误是因为目录BASE_DIR / "static" 不存在。 '/static/'也没有

    要解决您的问题,请从STATICFILES_DIRS 中删除这两个,或者将STATICFILES_DIRS 一起删除。查看您的项目是没有必要的。

    STATICFILES_DIRS = [
    
    ]
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-04
      • 2018-08-18
      • 2020-12-27
      • 1970-01-01
      • 2021-08-07
      • 1970-01-01
      • 2019-04-16
      • 2022-01-25
      相关资源
      最近更新 更多