Python django应用程序在heroku TypeError上崩溃:应为str、bytes或os.PathLike对象,而不是函数

Python django应用程序在heroku TypeError上崩溃:应为str、bytes或os.PathLike对象,而不是函数,python,django,heroku,Python,Django,Heroku,我的django应用程序无法在heroku上运行,我不知道为什么 我从heroku获得以下错误代码: 2019-02-19T17:36:16.022570+00:00 app[web.1]: TypeError: expected str, bytes or os.PathLike object, not function 然后,当我导航到该站点时,我会看到: 2019-02-19T17:37:21.630743+00:00 heroku[router]: at=error code=H1

我的
django
应用程序无法在
heroku
上运行,我不知道为什么

我从heroku获得以下错误代码:

2019-02-19T17:36:16.022570+00:00 app[web.1]:
  TypeError: expected str, bytes or os.PathLike object, not function
然后,当我导航到该站点时,我会看到:

2019-02-19T17:37:21.630743+00:00 heroku[router]: at=error code=H10 
  desc="App crashed" method=GET path="/" host=full-stack-frameworks-django.herokuapp.com
  request_id=9d5b7ef6-790f-4584-921a-d1392842c93a fwd="109.78.21.112" 
  dyno= connect= service= status=503 bytes= protocol=https
这是我的设置.py文件

import os
# from dotenv import load_dotenv
import psycopg2
import dj_database_url

DATABASE_URL = os.environ['DATABASE_URL']
conn = psycopg2.connect(DATABASE_URL, sslmode='require')

# WHITENOISE_USE_FINDERS = True

# dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
# load_dotenv(dotenv_path)

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY')

# 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',
    'django_forms_bootstrap',
    'home',
    'accounts',
    'blogposts',
    'tickets',
    'payments',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.storage.CompressedManifestStaticFilesStorage',
    '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 = 'IssueTracker.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        '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',
                'django.template.context_processors.media',
            ],
        },
    },
]

WSGI_APPLICATION = 'IssueTracker.wsgi.application'


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

DATABASES={}

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

# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.sqlite3',
#         'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
#     }
# }


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

STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static')
]
STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')


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

MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = os.environ.get('EMAIL_ADDRESS')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASSWORD')
EMAIL_PORT = 587

# TEST KEYS
STRIPE_SECRET_KEY = os.environ.get('STRIPE_SECRET_KEY')
#
STRIPE_PUBLISHABLE_KEY = os.environ.get('STRIPE_PUBLISHABLE_KEY')
#
我有一个我认为是正确的procfile:

web: gunicorn IssueTracker.wsgi:application

这是我第一篇关于StackOverflow的文章,如果我需要提供更多信息,请告诉我。

我认为Heroku数据库的URL与您的想法不同。它不是DB服务器的URL。相反,它指向将在Django数据库设置中使用的配置信息:

DATABASES = {
    'default': dj_database_url.config(
        default=environ.get('DATABASE_URL')
    )
}

考虑到这一点,我不能说这是否是错误——这只是我在您的代码中看到的。祝你好运

所以我昨天就知道了。该错误是由于
whitenoise
中间件在
settings.py
文件中未正确配置所致

而不是

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.storage.CompressedManifestStaticFilesStorage',
....
....
我本来应该

MIDDLEWARE = [
        'django.middleware.security.SecurityMiddleware',
        'whitenoise.middleware.WhiteNoiseMiddleware',
    ....
    ....
如果要将压缩应用于静态文件,则实际应将
CompressedManifestStaticFilesStorage
应用于
settings.py
中的STSTICFILES\u存储变量