【问题标题】:Heroku returns desc="No web processes running" while running Django even with a Procfile?Heroku 在使用 Procfile 运行 Django 时返回 desc="No web processes running"?
【发布时间】:2021-09-11 15:09:04
【问题描述】:

在尝试连接到应用程序时遇到 Django 返回 at=error code=H14 desc="No web processes running" method=GET path="/set-crf/" host=appxxxx.herokuapp.com request_id=8c8ded0a-5470-46c3-b371-29602549d533 fwd="100.38.206.95" dyno= connect= service= status=503 bytes= protocol=https 的问题。添加 Procfile、导入 django-heroku 并设置 requirements.txt 后,似乎没有任何效果。到目前为止,这是我所拥有的:

相关代码

过程文件:

web: gunicorn rpa_django.wsgi

settings.py:

import django_heroku
from pathlib import Path
from corsheaders.defaults import default_headers
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 = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

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

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'corsheaders',
    'pc_algo',
]

MIDDLEWARE = [
    ...,
    "corsheaders.middleware.CorsMiddleware",
    "django.middleware.common.CommonMiddleware",
    ...,
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'corsheaders.middleware.CorsMiddleware',
]

ROOT_URLCONF = 'rpa_django.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 = 'rpa_django.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


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = '/static/'

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

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

# CORS configuration
CORS_ALLOWED_ORIGINS = ["http://localhost:3000"]
CORS_ALLOW_CREDENTIALS = True
CORS_ALLOW_HEADERS = list(default_headers) + ['X-CSRFToken']
CORS_EXPOSED_HEADERS = ['Set-Cookie']

# CSRF configurations
CSRF_TRUSTED_ORIGINS = ['localhost:3000'] 
CSRF_COOKIE_HTTPONLY = False
CSRF_COOKIE_SAMESITE = 'None'
CSRF_COOKIE_SECURE = True

django_heroku.settings(locals())

我尝试了什么

  1. 清空 requirements.txt,部署应用程序,然后冻结以重置 Herokus 缓存。
  2. 调整 Procfile,将其重命名为不带大写字母的 procfile。没有效果。
  3. heroku ps:scale web=1。 Heroku 仍然显示This app has no process types yet Add a Procfile to your app in order to define its process types.

我不确定还能做什么。我认为问题可能出在我的 Procfile 中,但我完全确定它具有正确的命名约定。我忽略了什么?

【问题讨论】:

    标签: django heroku


    【解决方案1】:

    对不起,这里的一切都是正确的,我唯一搞砸的是 Procfile 的位置。我不敢相信我花了 3 个小时在这上面

    【讨论】:

      猜你喜欢
      • 2021-10-10
      • 2020-02-05
      • 2021-04-07
      • 2021-03-19
      • 2019-02-14
      • 1970-01-01
      • 2016-03-30
      • 2015-09-08
      • 2022-10-16
      相关资源
      最近更新 更多