我有在LocalHost上运行的Django App,但是当我尝试部署Heroku时,出现ModuleNotFoundError错误:没有名为“ social_django”的模块。 我的settings.py有这个,我已经通过pip3安装了social-auth-app-django。我也运行了manage.py迁移,没有任何问题。
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'whitenoise.runserver_nostatic',
'crispy_forms',
'social_django',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'social_auth.middleware.SocialAuthExceptionMiddleware',
]
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',
'social_django.context_processors.backends',
'social_django.context_processors.login_redirect',
],
},
},
]
AUTHENTICATION_BACKENDS = [
'social_core.backends.twitter.TwitterOAuth',
'social_core.backends.facebook.FacebookOAuth2',
'django.contrib.auth.backends.ModelBackend',
]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') # new!
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
冻结冻结返回以下相关材料
social-auth-app-django==2.1.0
social-auth-core==1.7.0
heroku logs
返回
app[web.1]: [2018-09-19 22:58:32 +0000] [10] [ERROR] Exception in worker process
app[web.1]: Traceback (most recent call last):
app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
app[web.1]: self.load_wsgi()
app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 129, in init_process
app[web.1]: worker.init_process()
app[web.1]: self.wsgi = self.app.wsgi()
app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
app[web.1]: self.callable = self.load()
app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
app[web.1]: return self.load_wsgiapp()
app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
app[web.1]: return util.import_app(self.app_uri)
app[web.1]: __import__(module)
app[web.1]: File "/app/smash_feed_project/wsgi.py", line 16, in <module>
app[web.1]: application = get_wsgi_application()
app[web.1]: File "/app/.heroku/python/lib/python3.6/site-
packages/django/core/wsgi.py", line 12, in get_wsgi_application
Traceback (most recent call last):
app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
app[web.1]: worker.init_process()
app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 129, in init_process
app[web.1]: self.load_wsgi()
app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
app[web.1]: self.wsgi = self.app.wsgi()
app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
app[web.1]: self.callable = self.load()
app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
app[web.1]: return self.load_wsgiapp()
app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
app[web.1]: return util.import_app(self.app_uri)
app[web.1]: __import__(module)
app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
app[web.1]: application = get_wsgi_application()
app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
app[web.1]: django.setup(set_prefix=False)
app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
app[web.1]: apps.populate(settings.INSTALLED_APPS)
app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/registry.py", line 89, in populate
app[web.1]: app_config = AppConfig.create(entry)
app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/config.py", line 90, in create
app[web.1]: module = import_module(entry)
app[web.1]: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
app[web.1]: ModuleNotFoundError: No module named 'social_django'
app[web.1]: [2018-09-19 22:58:32 +0000] [11] [INFO] Worker exiting (pid: 11)
app[web.1]: [2018-09-19 22:58:32 +0000] [4] [INFO] Shutting down: Master
app[web.1]: [2018-09-19 22:58:32 +0000] [4] [INFO] Reason: Worker failed to boot.
heroku[web.1]: Process exited with status 3
heroku[web.1]: State changed from up to crashed
app[api]: Build succeeded
很抱歉heroku日志的长度。我已经尝试了几种在stackoverflow上发现的不同方法,但是都没有用。我什至尝试撤消提交并重做部署到Heroku的步骤。我仍然遇到相同的错误。
编辑:在下面添加了我的点子文件
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
django = "*"
django-crispy-forms = "*"
gunicorn = "*"
whitenoise = "*"
[dev-packages]
pylint = "*"
[requires]
python_version = "3.6"