我要做什么?
我正在尝试将Django应用程序部署到heroku。
出了什么问题?
将我的应用程序上传到heroku之后。我尝试访问它,但得到一个Application Error
,其中也提到了该命令heroku logs --tail
,以获取错误的详细信息。因此,我运行了该命令,并获得了包含以下详细信息的日志(它在日志中显示了很多内容,但仅显示了一些内容):
2018-08-27T20:03:18.139298+00:00 app[web.1]: [2018-08-27 20:03:18 +0000] [11] [ERROR] Exception in worker process
2018-08-27T20:03:18.139347+00:00 app[web.1]: Traceback (most recent call last):
2018-08-27T20:03:18.139351+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2018-08-27T20:03:18.139356+00:00 app[web.1]: worker.init_process()
2018-08-27T20:03:18.139358+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
2018-08-27T20:03:18.139360+00:00 app[web.1]: self.load_wsgi()
2018-08-27T20:03:18.139361+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2018-08-27T20:03:18.139363+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2018-08-27T20:03:18.139365+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2018-08-27T20:03:18.139366+00:00 app[web.1]: self.callable = self.load()
2018-08-27T20:03:18.139368+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2018-08-27T20:03:18.139370+00:00 app[web.1]: return self.load_wsgiapp()
2018-08-27T20:03:18.139371+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2018-08-27T20:03:18.139373+00:00 app[web.1]: return util.import_app(self.app_uri)
2018-08-27T20:03:18.139375+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 350, in import_app
2018-08-27T20:03:18.139377+00:00 app[web.1]: __import__(module)
2018-08-27T20:03:18.139379+00:00 app[web.1]: File "/app/ditook/wsgi.py", line 16, in <module>
2018-08-27T20:03:18.139380+00:00 app[web.1]: application = get_wsgi_application()
2018-08-27T20:03:18.139382+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
2018-08-27T20:03:18.139384+00:00 app[web.1]: django.setup(set_prefix=False)
2018-08-27T20:03:18.139385+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
2018-08-27T20:03:18.139387+00:00 app[web.1]: apps.populate(settings.INSTALLED_APPS)
2018-08-27T20:03:18.139388+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
2018-08-27T20:03:18.139390+00:00 app[web.1]: app_config = AppConfig.create(entry)
2018-08-27T20:03:18.139391+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/apps/config.py", line 94, in create
2018-08-27T20:03:18.139393+00:00 app[web.1]: module = import_module(entry)
2018-08-27T20:03:18.139394+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/importlib/__init__.py", line 37, in import_module
2018-08-27T20:03:18.139396+00:00 app[web.1]: __import__(name)
2018-08-27T20:03:18.139397+00:00 app[web.1]: ImportError: No module named django_visitor_information
在日志中的每个地方,我都看到ImportError: No module named django_visitor_information
被提及。
settings.py:
INSTALLED_APPS = [
'Authentication.apps.AuthenticationConfig',
'django_visitor_information',
...,]
MIDDLEWARE = [
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'Authentication.timezone_middleware.TimezoneMiddleware',
...,]
SETTINGS_PATH = os.path.dirname(os.path.dirname(__file__))
WSGI_APPLICATION = 'myproject.wsgi.application'
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
import dj_database_url
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATICFILES_DIRS = [
os.path.join(BASE_DIR,"static"),
]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
MEDIA_ROOT = os.path.join(BASE_DIR, 'static/media/Img')
MEDIA_URL = '/static/media/'
项目结构:
- myproject
- myproject
- migrations
- _init_.py
- admin.py
- models.py
- settings.py
- urls.py
- views.py
- wsgi.py
- static
- templates
- db.sqlite3
- GeolP.dat // this is used by django_visitor_information
- manage.py
- Procfile
- requirements.txt
- runtime.txt
我还尝试将init.py
个应用中的django_visitor_information
设置为空。因为我在this帖子中看到了它。但这仍然无济于事。
任何帮助将不胜感激。