这是我收到的错误消息:
[2021-05-30T10:39:25.931285815Z] -----> $ python manage.py collectstatic --noinput
[2021-05-30T10:39:26.203723037Z] Traceback (most recent call last):
[2021-05-30T10:39:26.216276562Z] File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 204, in fetch_command
[2021-05-30T10:39:26.218321657Z] app_name = commands[subcommand]
[2021-05-30T10:39:26.220104587Z] KeyError: 'collectstatic'
[2021-05-30T10:39:26.224315059Z] During handling of the above exception, another exception occurred:
[2021-05-30T10:39:26.226203429Z] Traceback (most recent call last):
[2021-05-30T10:39:26.228807809Z] File "/workspace/manage.py", line 22, in <module>
[2021-05-30T10:39:26.229778775Z] main()
[2021-05-30T10:39:26.232093136Z] File "/workspace/manage.py", line 18, in main
[2021-05-30T10:39:26.234133309Z] execute_from_command_line(sys.argv)
[2021-05-30T10:39:26.239913239Z] File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
[2021-05-30T10:39:26.241335162Z] utility.execute()
[2021-05-30T10:39:26.246299500Z] File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 375, in execute
[2021-05-30T10:39:26.249345439Z] self.fetch_command(subcommand).run_from_argv(self.argv)
[2021-05-30T10:39:26.255367504Z] File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 211, in fetch_command
[2021-05-30T10:39:26.256776257Z] settings.INSTALLED_APPS
[2021-05-30T10:39:26.263303743Z] File "/app/.heroku/python/lib/python3.9/site-packages/django/conf/__init__.py", line 57, in __getattr__
[2021-05-30T10:39:26.263988051Z] self._setup(name)
[2021-05-30T10:39:26.269528994Z] File "/app/.heroku/python/lib/python3.9/site-packages/django/conf/__init__.py", line 44, in _setup
[2021-05-30T10:39:26.271917901Z] self._wrapped = Settings(settings_module)
[2021-05-30T10:39:26.276311739Z] File "/app/.heroku/python/lib/python3.9/site-packages/django/conf/__init__.py", line 107, in __init__
[2021-05-30T10:39:26.279100519Z] mod = importlib.import_module(self.SETTINGS_MODULE)
[2021-05-30T10:39:26.283428429Z] File "/app/.heroku/python/lib/python3.9/importlib/__init__.py", line 127, in import_module
[2021-05-30T10:39:26.286322693Z] return _bootstrap._gcd_import(name[level:], package, level)
[2021-05-30T10:39:26.289320899Z] File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
[2021-05-30T10:39:26.292269277Z] File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
[2021-05-30T10:39:26.295544601Z] File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
[2021-05-30T10:39:26.298809741Z] File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
[2021-05-30T10:39:26.302382236Z] File "<frozen importlib._bootstrap_external>", line 790, in exec_module
[2021-05-30T10:39:26.306047614Z] File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
[2021-05-30T10:39:26.313158573Z] File "/workspace/onlineminer/settings.py", line 5, in <module>
[2021-05-30T10:39:26.313914416Z] import dj_database_url
[2021-05-30T10:39:26.316344819Z] ModuleNotFoundError: No module named 'dj_database_url'
[2021-05-30T10:39:26.430685413Z]
[2021-05-30T10:39:26.430715962Z] ! Error while running '$ python manage.py collectstatic --noinput'.
[2021-05-30T10:39:26.431050775Z] See traceback above for details.
[2021-05-30T10:39:26.431093474Z]
[2021-05-30T10:39:26.431140200Z] You may need to update application code to resolve this error.
[2021-05-30T10:39:26.431228840Z] Or, you can disable collectstatic for this application:
[2021-05-30T10:39:26.431252873Z]
[2021-05-30T10:39:26.431304406Z] $ heroku config:set DISABLE_COLLECTSTATIC=1
[2021-05-30T10:39:26.431310799Z]
[2021-05-30T10:39:26.431379566Z] https://devcenter.heroku.com/articles/django-assets
[2021-05-30T10:39:26.447332416Z] ERROR: failed to build: exit status 1
[2021-05-30T10:39:29.594971932Z]
[2021-05-30T10:39:29.595001801Z] For documentation on the buildpacks used to build your app, please see:
[2021-05-30T10:39:29.595012993Z] Python: https://do.co/apps-buildpack-python
[2021-05-30T10:39:29.597607612Z]
[2021-05-30T10:39:29.598132257Z] ! Build failed (145)
我的 settings.py 文件:
from django.core.management.utils import get_random_secret_key
from pathlib import Path
import os
import sys
import dj_database_url
# 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 = os.getenv("DJANGO_SECRET_KEY", get_random_secret_key())
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv("DEBUG", "False") == "True"
ALLOWED_HOSTS = os.getenv("DJANGO_ALLOWED_HOSTS", "127.0.0.1,localhost").split(",")
# Application definition
INSTALLED_APPS = [
"users.apps.UsersConfig",
'miner.apps.MinerConfig',
"crispy_bootstrap5",
"crispy_forms",
'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 = 'onlineminer.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 = 'onlineminer.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DEVELOPMENT_MODE = os.getenv("DEVELOPMENT_MODE", "False") == "True"
if DEVELOPMENT_MODE is True:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}
elif len(sys.argv) > 0 and sys.argv[1] != 'collectstatic':
if os.getenv("DATABASE_URL", None) is None:
raise Exception("DATABASE_URL environment variable not defined")
DATABASES = {
"default": dj_database_url.parse(os.environ.get("DATABASE_URL")),
}
# 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_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
CRISPY_TEMPLATE_PACK = "bootstrap5"
LOGIN_REDIRECT_URL = "index"
LOGOUT_REDIRECT_URL = "index"
正如您在 settings.py 文件中看到的,我已经设置了 STATIC_ROOT,但我仍然收到错误消息。我试图解决这个问题,但无法让它工作。我以前用这种设置文件部署过,所以我认为这只是我犯的一个小错误。提前致谢