python - 部署到 heroku 的 Django 错误

标签 python django heroku

嘿,我是 heroku 和 django 的新手,在学习这些教程时我一直在解决一个问题: Tutorial 1 - django girl , Tutorial 2-heroku

我按照所有步骤将现有项目部署到 heroku,但我不断收到此消息:

    remote:      $ python manage.py collectstatic --noinput
remote:        Traceback (most recent call last):
remote:          File "manage.py", line 9, in <module>
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/__init__.py", line 302, in execute
remote:            settings.INSTALLED_APPS
remote:          File "/app/.heroku/python/lib/python3.4/site-packages/django/conf/__init__.py", line 55, in __getattr__
remote:            self._setup(name)
remote:          File "/app/.heroku/python/lib/python3.4/site-packages/django/conf/__init__.py", line 43, in _setup
remote:            self._wrapped = Settings(settings_module)
remote:          File "/app/.heroku/python/lib/python3.4/site-packages/django/conf/__init__.py", line 99, in __init__
remote:            mod = importlib.import_module(self.SETTINGS_MODULE)
remote:          File "/app/.heroku/python/lib/python3.4/importlib/__init__.py", line 104, in import_module
remote:            return _bootstrap._gcd_import(name[level:], package, level)
remote:          File "<frozen importlib._bootstrap>", line 2231, in _gcd_import
remote:          File "<frozen importlib._bootstrap>", line 2214, in _find_and_load
remote:          File "<frozen importlib._bootstrap>", line 2201, in _find_and_load_unlocked
remote:        ImportError: No module named 'mysite.settings'
remote:
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.
remote:        See traceback above for details.
remote:
remote:        You may need to update application code to resolve this error.
remote:        Or, you can disable collectstatic for this application:
remote:
remote:           $ heroku config:set DISABLE_COLLECTSTATIC=1
remote:
remote:        https://devcenter.heroku.com/articles/django-assets
remote:
remote:  !     Push rejected, failed to compile Python app
remote:
remote: Verifying deploy...
remote:
remote: !       Push rejected to mysitefp1.
remote:
To https://git.heroku.com/mysitefp1.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/mysitefp1.git'

我的 wsgi.py:

    import os
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

    from django.core.wsgi import get_wsgi_application
    from whitenoise.django import DjangoWhiteNoise

    application = get_wsgi_application()
    application = DjangoWhiteNoise(application)

my settings.py
"""
Django settings for mysite project.

Generated by 'django-admin startproject' using Django 1.8.5.

For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""

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


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '************************'

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

DJANGO_SETTINGS_MODULE="mysite.mysite.settings"


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.facebook',
    'address',
    'BusinessApp',
    'BaseApp',
    'UserApp',
    'conversation',
    'django_libs',
    'widget_tweaks',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'mysite.urls'

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



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

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


# Internationalization
# https://docs.djangoproject.com/en/1.8/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/1.8/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media')
MEDIA_URL = '/media/'

AUTHENTICATION_BACKENDS = (
    # Needed to login by username in Django admin, regardless of `allauth`
    "django.contrib.auth.backends.ModelBackend",
    # `allauth` specific authentication methods, such as login by e-mail
    "allauth.account.auth_backends.AuthenticationBackend"
)

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.core.context_processors.request",
    "django.contrib.auth.context_processors.auth",
    "allauth.account.context_processors.account",
    "allauth.socialaccount.context_processors.socialaccount",
)

# auth and allauth settings
LOGIN_REDIRECT_URL = '/'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
SITE_ID=1


STATICFILES_DIRS = [
    os.path.join(PROJECT_ROOT, 'static'),
    # os.path.join(PROJECT_ROOT, 'media'),
    # os.path.join(BASE_DIR, "static"),
    # '/static/',
    # '',
]

import dj_database_url
WSGI_APPLICATION = 'mysite.wsgi.application'

SOCIALACCOUNT_ADAPTER = 'BaseApp.adapters.ProfileAdapter'
ACCOUNT_USERNAME_REQUIRED = False
LOGIN_URL = "/"


DATABASES['default'] = dj_database_url.config()

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

ALLOWED_HOSTS = ['*']

DEBUG = False

try:
    from .local_settings import *
except ImportError:
    pass


STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

# Update database configuration with $DATABASE_URL.
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)

我的过程文件:

web: gunicorn mysite.wsgi --log-file -

我的要求.txt:

defusedxml==0.4.1
dj-database-url==0.4.1
Django==1.9.5
django-address==0.1.5
django-allauth==0.25.2
django-conversation==1.4.6
django-libs==1.67.4
django-oauth==1.1
django-staticfiles==1.2.1
django-widget-tweaks==1.4.1
gunicorn==19.4.5
oauthlib==1.1.1
Pillow==3.2.0
PyJWT==1.4.0
python-social-auth==0.2.19
python3-openid==3.0.10
requests==2.10.0
requests-oauthlib==0.6.1
six==1.10.0
whitenoise==3.0
psycopg2==2.5.4

我连续 3 天都不知道发生了什么事!请帮帮我

P.S 如果我尝试禁用静态,当我尝试迁移时同样的错误再次发生。

最佳答案

我遇到了同样的问题,就是 git 不知何故没有将设置文件添加到我项目中的存储库中,我解决这个问题的方法是创建一个新的 django 项目和一个新的存储库,还要检查你是否有你的.gitignore 文件中的设置文件。始终使用 git status 检查哪些更改将被提交,如果你需要的一切都在那里,那么它应该可以工作。

关于python - 部署到 heroku 的 Django 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36973955/

相关文章:

python - python 中循环条件出错时如何继续?

python - 如何从使用 .loc 找到的特定行中提取值以返回变量

python - 提取两个子字符串之间匹配的字符串部分

django - 信号m2m_changed和post_remove的错误

ruby-on-rails - PostgreSQL "could not identify an equality operator for type json"的 Heroku 错误

python - 忽略对角线的 Numpy 数组的最小值

python - 我怎样才能在python中获得-ve数的无符号大小

javascript - 如何将 AngularJS 模板转换为字符串?

.net - 使用Docker部署到Heroku时.Net Core 2.1 App崩溃

android - Heroku + mongolab 沙箱应用程序部署在 Play 商店中