0

我正在编写一个使用 Webpack 构建的 TypeScript/React 前端和由 Django 运行的后端的项目。运行npm run build,然后./manage.py collectstatic在本地正常工作。但是我在尝试在 Heroku 上部署我的项目时遇到了问题。我知道这个问题已经被问过很多次了,但没有其他解决方案对我有用。

这是我跑步时得到的git push heroku main

Enumerating objects: 19, done.
Counting objects: 100% (19/19), done.
Delta compression using up to 4 threads
Compressing objects: 100% (9/9), done.
Writing objects: 100% (10/10), 1.26 KiB | 644.00 KiB/s, done.
Total 10 (delta 7), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpacks:
remote:        1. heroku/nodejs
remote:        2. heroku/python
remote: -----> Node.js app detected
remote:        
remote: -----> Creating runtime environment
remote:        
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NODE_VERBOSE=false
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote:        engines.node (package.json):  unspecified
remote:        engines.npm (package.json):   unspecified (use default)
remote:
remote:        Resolving node version 14.x...
remote:        Downloading and installing node 14.17.1...
remote:        Using default npm version: 6.14.13
remote:        
remote: -----> Restoring cache
remote:        - node_modules
remote:        
remote: -----> Installing dependencies
remote:        Installing node modules
remote:        added 5 packages in 0.409s
remote:        
remote: -----> Build
remote:        
remote: -----> Caching build
remote:        - node_modules
remote:        
remote: -----> Pruning devDependencies
remote:        audited 5 packages in 0.353s
remote:        found 0 vulnerabilities
remote:
remote:        
remote: -----> Build succeeded!
remote: -----> Python app detected
remote: -----> Using Python version specified in Pipfile.lock
remote: cp: cannot stat '/tmp/build_a2c93ee9/requirements.txt': No such file or directory
remote: -----> Using cached install of python-3.9.6
remote: -----> Installing pip 20.2.4, setuptools 47.1.1 and wheel 0.36.2
remote:        Skipping installation, as Pipfile.lock hasn't changed since last deploy.
remote: -----> Installing SQLite3
remote: -----> $ python manage.py collectstatic --noinput
remote:        152 static files copied to '/tmp/build_a2c93ee9/staticfiles', 476 post-processed.
remote: 
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 111.1M
remote: -----> Launching...
remote:        Released v14
remote:        https://myproject.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/myproject.git
 + 60592b5...2777b0e main -> main (forced update)

settings.py(这是项目中唯一的设置文件):

import django_heroku
import dj_database_url
import os
import subprocess
import whitenoise

from datetime import timedelta

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

SECRET_KEY = os.environ.get('SECRET_KEY')

ALLOWED_HOSTS = [ 'localhost' ]

CORS_ORIGIN_WHITELIST = [
    'http://localhost:3000',
    'http://localhost:8000',
    'http://localhost:8080',
    'http://localhost:5432',
]

CORS_ALLOW_HEADERS = (
        'x-requested-with',
        'content-type',
        'accept',
        'origin',
        'authorization',
        'x-csrftoken'
)

REACT_APP_API_ENDPOINT = 'http://localhost:8000/'

DEBUG = True

if os.environ.get('NODE_ENV'):
    DEBUG = False

    REACT_APP_API_ENDPOINT = 'http://myproject.com/'

    ALLOWED_HOSTS = [ '.herokuapp.com', 'myproject.com' ]

    CORS_ORIGIN_WHITELIST = [
        'http://myproject.com/',
        'http://myproject.herokuapp.com/',
        'http://*.herokuapp.com/',
    ]



# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'authentication',
    'corsheaders',
    'rest_framework',
    'notebooks',
    'frontend',
]

MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',
    '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 = 'core.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 = 'core.wsgi.application'



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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.environ.get('DATABASE_NAME'),
        'USER': os.environ.get('DB_OWNER_USERNAME'),
        'PASSWORD': os.environ.get('DB_OWNER_PASSWORD'),
        'HOST': os.environ.get('DATABASE_URL'),
        'PORT': os.environ.get('DB_PORT'),
    }
}

if os.environ.get('NODE_ENV'):
    credentials = subprocess.check_output([
        '/bin/bash',
        '-c',
        'heroku config:get DATABASE_URL -a myproject',
    ], shell=True).decode('utf-8')

    DATABASES['default'] = dj_database_url.config(default=credentials, conn_max_age=600)



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

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'frontend', 'static', 'frontend'),
)

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'



# Miscellaneous

MAX_SLUG_LENGTH = 15

APPEND_SLASH = True

AUTH_USER_MODEL = 'authentication.MyProjectUser'

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    )
}

SIMPLE_JWT = {
    'ACCESS_TOKEN_LIFETIME': timedelta(hours=24),
    'REFRESH_TOKEN_LIFETIME': timedelta(days=30),
    'ROTATE_REFRESH_TOKENS': True,
    'BLACKLIST_AFTER_ROTATION': False,
    'ALGORITHM': 'HS256',
    'SIGNING_KEY': SECRET_KEY,
    'VERIFYING_KEY': None,
    'AUTH_HEADER_TYPES': ('JWT',),
    'USER_ID_FIELD': 'email',
    'USER_ID_CLAIM': 'login_email',
    'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
    'TOKEN_TYPE_CLAIM': 'token_type',
}

# Logging

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': ('%(asctime)s [%(process)d] [%(levelname)s] '
                       'pathname=%(pathname)s lineno=%(lineno)s '
                       'funcname=%(funcName)s %(message)s'),
            'datefmt': '%Y-%m-%d %H:%M:%S'
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        }
    },
    'handlers': {
        'null': {
            'level': 'DEBUG',
            'class': 'logging.NullHandler',
        },
        'console': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose'
        }
    },
    'loggers': {
        'django': {
            'handlers': ['console'],
            'level': 'DEBUG',
            'propagate': True,
        },
        'django.request': {
            'handlers': ['console'],
            'level': 'DEBUG',
            'propagate': False,
        },
    }
}

django_heroku.settings(locals(), logging=False, databases=False)

错误信息:

2021-06-30T16:23:00.826686+00:00 app[web.1]: raise ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)
2021-06-30T16:23:00.826687+00:00 app[web.1]: ValueError: Missing staticfiles manifest entry for 'frontend/favicon.ico'
2021-06-30T16:23:00.827738+00:00 heroku[router]: at=info method=GET path="/" host=myproject.herokuapp.com request_id=503bf0f8-f9a7-4fba-b8e8-5829d66536ba fwd="37.120.244.101" dyno=web.1 connect=2ms service=495ms status=500 bytes=227 protocol=https
2021-06-30T16:23:00.827751+00:00 app[web.1]: 10.136.167.231 - - [30/Jun/2021:16:23:00 +0000] "GET / HTTP/1.1" 500 27 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"

具有完整回溯的日志:

2021-06-30T16:05:14.449877+00:00 app[web.1]: response = get_response(request)
2021-06-30T16:05:14.449879+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/core/handlers/base.py", line 115, in _get_response
2021-06-30T16:05:14.449880+00:00 app[web.1]: response = self.process_exception_by_middleware(e, request)
2021-06-30T16:05:14.449881+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/core/handlers/base.py", line 113, in _get_response
2021-06-30T16:05:14.449881+00:00 app[web.1]: response = wrapped_callback(request, *callback_args, **callback_kwargs)
2021-06-30T16:05:14.449882+00:00 app[web.1]: File "/app/frontend/views.py", line 4, in index
2021-06-30T16:05:14.449882+00:00 app[web.1]: return render(request, 'index.html')
2021-06-30T16:05:14.449882+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/shortcuts.py", line 36, in render
2021-06-30T16:05:14.449883+00:00 app[web.1]: content = loader.render_to_string(template_name, context, request, using=using)
2021-06-30T16:05:14.449884+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/loader.py", line 62, in render_to_string
2021-06-30T16:05:14.449884+00:00 app[web.1]: return template.render(context, request)
2021-06-30T16:05:14.449884+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/backends/django.py", line 61, in render
2021-06-30T16:05:14.449885+00:00 app[web.1]: return self.template.render(context)
2021-06-30T16:05:14.449885+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/base.py", line 171, in render
2021-06-30T16:05:14.449886+00:00 app[web.1]: return self._render(context)
2021-06-30T16:05:14.449886+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/base.py", line 163, in _render
2021-06-30T16:05:14.449886+00:00 app[web.1]: return self.nodelist.render(context)
2021-06-30T16:05:14.449887+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/base.py", line 937, in render
2021-06-30T16:05:14.449887+00:00 app[web.1]: bit = node.render_annotated(context)
2021-06-30T16:05:14.449887+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/base.py", line 904, in render_annotated
2021-06-30T16:05:14.449888+00:00 app[web.1]: return self.render(context)
2021-06-30T16:05:14.449888+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/templatetags/static.py", line 106, in render
2021-06-30T16:05:14.449889+00:00 app[web.1]: url = self.url(context)
2021-06-30T16:05:14.449889+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/templatetags/static.py", line 103, in url
2021-06-30T16:05:14.449889+00:00 app[web.1]: return self.handle_simple(path)
2021-06-30T16:05:14.449890+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/templatetags/static.py", line 118, in handle_simple
2021-06-30T16:05:14.449890+00:00 app[web.1]: return staticfiles_storage.url(path)
2021-06-30T16:05:14.449890+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 153, in url
2021-06-30T16:05:14.449891+00:00 app[web.1]: return self._url(self.stored_name, name, force)
2021-06-30T16:05:14.449891+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 132, in _url
2021-06-30T16:05:14.449892+00:00 app[web.1]: hashed_name = hashed_name_func(*args)
2021-06-30T16:05:14.449892+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 420, in stored_name
2021-06-30T16:05:14.449892+00:00 app[web.1]: raise ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)
2021-06-30T16:05:14.449893+00:00 app[web.1]: ValueError: Missing staticfiles manifest entry for 'frontend/favicon.ico'
2021-06-30T16:05:14.454870+00:00 app[web.1]: 10.181.54.2 - - [30/Jun/2021:16:05:14 +0000] "GET / HTTP/1.1" 500 27 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
2021-06-30T16:05:14.455485+00:00 heroku[router]: at=info method=GET path="/" host=myproject.herokuapp.com request_id=ee6c5f47-b78a-4201-9d14-65730c6e5f91 fwd="37.120.244.101" dyno=web.1 connect=0ms service=10921ms status=500 bytes=227 protocol=https
2021-06-30T16:16:23.000000+00:00 app[api]: Build started by user jpaulvalen@gmail.com
2021-06-30T16:16:47.000000+00:00 app[api]: Build failed -- check your build output: https://dashboard.heroku.com/apps/dc89d2bf-8113-4bc6-a61d-89c7c127893f/activity/builds/2002371a-a4af-46cc-94f0-31425feb0ea5
2021-06-30T16:21:33.000000+00:00 app[api]: Build started by user jpaulvalen@gmail.com
2021-06-30T16:22:22.483318+00:00 app[api]: Release v14 created by user jpaulvalen@gmail.com
2021-06-30T16:22:22.483318+00:00 app[api]: Deploy 2777b0e3 by user jpaulvalen@gmail.com
2021-06-30T16:22:23.366584+00:00 heroku[web.1]: Restarting
2021-06-30T16:22:23.388293+00:00 heroku[web.1]: State changed from up to starting
2021-06-30T16:22:24.657187+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2021-06-30T16:22:24.835654+00:00 app[web.1]: [2021-06-30 16:22:24 +0000] [31] [INFO] Worker exiting (pid: 31)
2021-06-30T16:22:24.835669+00:00 app[web.1]: [2021-06-30 16:22:24 +0000] [32] [INFO] Worker exiting (pid: 32)
2021-06-30T16:22:24.836132+00:00 app[web.1]: [2021-06-30 16:22:24 +0000] [4] [WARNING] Worker with pid 27 was terminated due to signal 15
2021-06-30T16:22:24.836510+00:00 app[web.1]: [2021-06-30 16:22:24 +0000] [4] [INFO] Handling signal: term
2021-06-30T16:22:24.842055+00:00 app[web.1]: [2021-06-30 16:22:24 +0000] [4] [WARNING] Worker with pid 31 was terminated due to signal 15
2021-06-30T16:22:24.845543+00:00 app[web.1]: [2021-06-30 16:22:24 +0000] [4] [WARNING] Worker with pid 32 was terminated due to signal 15
2021-06-30T16:22:24.937231+00:00 app[web.1]: [2021-06-30 16:22:24 +0000] [4] [INFO] Shutting down: Master
2021-06-30T16:22:25.730105+00:00 heroku[web.1]: Process exited with status 0
2021-06-30T16:22:36.000000+00:00 app[api]: Build succeeded
2021-06-30T16:22:37.995504+00:00 heroku[web.1]: Starting process with command `gunicorn core.wsgi`
2021-06-30T16:22:43.648378+00:00 app[web.1]: [heroku-exec] Starting
2021-06-30T16:22:44.744285+00:00 app[web.1]: [2021-06-30 16:22:44 +0000] [4] [INFO] Starting gunicorn 20.1.0
2021-06-30T16:22:44.744326+00:00 app[web.1]: [2021-06-30 16:22:44 +0000] [4] [INFO] Listening at: http://0.0.0.0:55456 (4)
2021-06-30T16:22:44.744326+00:00 app[web.1]: [2021-06-30 16:22:44 +0000] [4] [INFO] Using worker: sync
2021-06-30T16:22:44.752288+00:00 app[web.1]: [2021-06-30 16:22:44 +0000] [36] [INFO] Booting worker with pid: 36
2021-06-30T16:22:44.784288+00:00 app[web.1]: [2021-06-30 16:22:44 +0000] [38] [INFO] Booting worker with pid: 38
2021-06-30T16:22:45.285535+00:00 heroku[web.1]: State changed from starting to up
2021-06-30T16:23:00.826647+00:00 app[web.1]: 2021-06-30 16:23:00 [36] [ERROR] pathname=/app/.heroku/python/lib/python3.9/site-packages/django/utils/log.py lineno=222 funcname=log_response Internal Server Error: /
2021-06-30T16:23:00.826669+00:00 app[web.1]: Traceback (most recent call last):
2021-06-30T16:23:00.826670+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/core/handlers/exception.py", line 34, in inner
2021-06-30T16:23:00.826671+00:00 app[web.1]: response = get_response(request)
2021-06-30T16:23:00.826672+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/core/handlers/base.py", line 115, in _get_response
2021-06-30T16:23:00.826673+00:00 app[web.1]: response = self.process_exception_by_middleware(e, request)
2021-06-30T16:23:00.826674+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/core/handlers/base.py", line 113, in _get_response
2021-06-30T16:23:00.826674+00:00 app[web.1]: response = wrapped_callback(request, *callback_args, **callback_kwargs)
2021-06-30T16:23:00.826675+00:00 app[web.1]: File "/app/frontend/views.py", line 4, in index
2021-06-30T16:23:00.826675+00:00 app[web.1]: return render(request, 'index.html')
2021-06-30T16:23:00.826676+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/shortcuts.py", line 36, in render
2021-06-30T16:23:00.826677+00:00 app[web.1]: content = loader.render_to_string(template_name, context, request, using=using)
2021-06-30T16:23:00.826677+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/loader.py", line 62, in render_to_string
2021-06-30T16:23:00.826677+00:00 app[web.1]: return template.render(context, request)
2021-06-30T16:23:00.826678+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/backends/django.py", line 61, in render
2021-06-30T16:23:00.826678+00:00 app[web.1]: return self.template.render(context)
2021-06-30T16:23:00.826679+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/base.py", line 171, in render
2021-06-30T16:23:00.826679+00:00 app[web.1]: return self._render(context)
2021-06-30T16:23:00.826679+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/base.py", line 163, in _render
2021-06-30T16:23:00.826680+00:00 app[web.1]: return self.nodelist.render(context)
2021-06-30T16:23:00.826680+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/base.py", line 937, in render
2021-06-30T16:23:00.826680+00:00 app[web.1]: bit = node.render_annotated(context)
2021-06-30T16:23:00.826681+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/template/base.py", line 904, in render_annotated
2021-06-30T16:23:00.826681+00:00 app[web.1]: return self.render(context)
2021-06-30T16:23:00.826682+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/templatetags/static.py", line 106, in render
2021-06-30T16:23:00.826682+00:00 app[web.1]: url = self.url(context)
2021-06-30T16:23:00.826683+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/templatetags/static.py", line 103, in url
2021-06-30T16:23:00.826683+00:00 app[web.1]: return self.handle_simple(path)
2021-06-30T16:23:00.826683+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/templatetags/static.py", line 118, in handle_simple
2021-06-30T16:23:00.826684+00:00 app[web.1]: return staticfiles_storage.url(path)
2021-06-30T16:23:00.826684+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 153, in url
2021-06-30T16:23:00.826685+00:00 app[web.1]: return self._url(self.stored_name, name, force)
2021-06-30T16:23:00.826685+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 132, in _url
2021-06-30T16:23:00.826685+00:00 app[web.1]: hashed_name = hashed_name_func(*args)
2021-06-30T16:23:00.826686+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 420, in stored_name
2021-06-30T16:23:00.826686+00:00 app[web.1]: raise ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)
2021-06-30T16:23:00.826687+00:00 app[web.1]: ValueError: Missing staticfiles manifest entry for 'frontend/favicon.ico'
2021-06-30T16:23:00.827738+00:00 heroku[router]: at=info method=GET path="/" host=myproject.herokuapp.com request_id=503bf0f8-f9a7-4fba-b8e8-5829d66536ba fwd="37.120.244.101" dyno=web.1 connect=2ms service=495ms status=500 bytes=227 protocol=https
2021-06-30T16:23:00.827751+00:00 app[web.1]: 10.136.167.231 - - [30/Jun/2021:16:23:00 +0000] "GET / HTTP/1.1" 500 27 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"

编辑:

这是我起飞whitenoise并将设置设置为时得到django_heroku的结果:staticfilesFalse

2021-06-30T16:35:15.953366+00:00 heroku[web.1]: State changed from starting to up
2021-06-30T16:35:25.051217+00:00 app[web.1]: 10.157.141.243 - - [30/Jun/2021:16:35:25 +0000] "GET / HTTP/1.1" 200 424 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
2021-06-30T16:35:25.051447+00:00 heroku[router]: at=info method=GET path="/" host=myproject.herokuapp.com request_id=f96afeff-7704-431c-afa6-aa364df09df9 fwd="37.120.244.101" dyno=web.1 connect=1ms service=497ms status=200 bytes=621 protocol=https
2021-06-30T16:35:25.267943+00:00 app[web.1]: 2021-06-30 16:35:25 [34] [WARNING] pathname=/app/.heroku/python/lib/python3.9/site-packages/django/utils/log.py lineno=222 funcname=log_response Not Found: /static/frontend/index.js 
2021-06-30T16:35:25.268873+00:00 app[web.1]: 10.157.141.243 - - [30/Jun/2021:16:35:25 +0000] "GET /static/frontend/index.js HTTP/1.1" 404 77 "https://myproject.herokuapp.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
2021-06-30T16:35:25.269357+00:00 heroku[router]: at=info method=GET path="/static/frontend/index.js" host=myproject.herokuapp.com request_id=306c0e1f-d1c5-4ebf-b15b-4f03f69ba424 fwd="37.120.244.101" dyno=web.1 connect=2ms service=134ms status=404 bytes=265 protocol=https

也许 Heroku 没有正确构建我的前端,所以collectstatic永远找不到它?

4

1 回答 1

0

It is done, just type in heroku open and if it is showing application error type heroku run python manage.py migrate

于 2021-07-05T18:17:43.437 回答