当本地版本找到时,Heroku找不到模块

时间:2019-02-09 20:14:11

标签: django heroku production

问题

因此,我创建了一个包含多个自制应用程序的网站。我现在想使用Heroku部署此网站。但是,这不起作用,因为我不断收到与Heroku找不到应用有关的错误。

当我使用

在本地运行网站时
python manage.py runserver

一切正常。

但是,当我尝试使用Heroku部署此网站时,出现错误(下面提供了堆栈跟踪)。

项目结构

towima
|   .gitignore
|   Procfile
|   README.md
|   requirements.txt
|   runtime.txt
|   tree.txt
|   
+---media_cdn
|   |   .DS_Store
|   |   
|   \---products
|                       
\---towima
    |   .DS_Store
    |   db.sqlite3
    |   manage.py
    |   pharma_locations.json
    |   __init__.py
    |   
    +---accounts
    |   |   admin.py
    |   |   apps.py
    |   |   forms.py
    |   |   models.py
    |   |   tests.py
    |   |   urls.py
    |   |   views.py
    |   |   __init__.py
    |   |   
    |   +---migrations
    +---api
    |   |   admin.py
    |   |   apps.py
    |   |   models.py
    |   |   serializers.py
    |   |   tests.py
    |   |   urls.py
    |   |   views.py
    |   |   __init__.py
    |   |   
    |   +---migrations
    |           
    +---orders
    |   |   admin.py
    |   |   apps.py
    |   |   forms.py
    |   |   models.py
    |   |   tests.py
    |   |   urls.py
    |   |   views.py
    |   |   __init__.py
    |   |   
    |   +---migrations
    |           
    +---pharmacies
    |   |   admin.py
    |   |   apps.py
    |   |   forms.py
    |   |   models.py
    |   |   tests.py
    |   |   urls.py
    |   |   views.py
    |   |   __init__.py
    |   |   
    |   +---migrations
    |           
    +---products
    |   |   admin.py
    |   |   apps.py
    |   |   forms.py
    |   |   models.py
    |   |   tests.py
    |   |   urls.py
    |   |   views.py
    |   |   __init__.py
    |   |   
    |   +---migrations
    |           
    +---static
    |               
    +---staticfiles
    +---templates
    |           
    \---towima
        |   admin.py
        |   models.py
        |   settings.py
        |   urls.py
        |   views.py
        |   wsgi.py
        |   __init__.py

我的Procfile

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

我的wsgi.py文件

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'towima.towima.settings')

application = get_wsgi_application()

以前,os.environ.setdefault包含“ towima.settings”,但我将其更改为现在的名称,因为否则,它将找不到正确的文件夹。

settings.py文件的相关部分

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'accounts',         # The account app
    'towima',           # Our own app
    'products',         #products App
    'pharmacies',       #Pharmacy App
    'orders',           #Orders App
    'rest_framework',
    'crispy_forms',
    'api',
]

我想问题就在这里。当我在本地运行该网站时,它会找到所有应用程序,但是当我在Heroku中尝试该网站时,会收到错误消息,即没有名为accounts的模块。当我发表评论以查看会发生什么时,它给我一个错误,即没有名为产品的模块。这使我相信它在错误的文件夹中查找,因为towima模块没有错误。当我将应用程序名称从'accounts'更改为'towima.accounts'时,它在本地崩溃,并且在Heroku上也不起作用。

堆栈跟踪

2019-02-09T19:37:45.956108+00:00 heroku[web.1]: Starting process with command `gunicorn towima.towima.wsgi --log-file -`
2019-02-09T19:37:47.980579+00:00 app[web.1]: [2019-02-09 19:37:47 +0000] [4] [INFO] Starting gunicorn 19.9.0
2019-02-09T19:37:47.981190+00:00 app[web.1]: [2019-02-09 19:37:47 +0000] [4] [INFO] Listening at: http://0.0.0.0:45237 (4)
2019-02-09T19:37:47.981279+00:00 app[web.1]: [2019-02-09 19:37:47 +0000] [4] [INFO] Using worker: sync
2019-02-09T19:37:47.986079+00:00 app[web.1]: [2019-02-09 19:37:47 +0000] [10] [INFO] Booting worker with pid: 10
2019-02-09T19:37:48.007337+00:00 app[web.1]: [2019-02-09 19:37:48 +0000] [11] [INFO] Booting worker with pid: 11
2019-02-09T19:37:48.242699+00:00 app[web.1]: [2019-02-09 19:37:48 +0000] [11] [ERROR] Exception in worker process
2019-02-09T19:37:48.242725+00:00 app[web.1]: Traceback (most recent call last):
2019-02-09T19:37:48.242727+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2019-02-09T19:37:48.242729+00:00 app[web.1]: worker.init_process()
2019-02-09T19:37:48.242730+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
2019-02-09T19:37:48.242732+00:00 app[web.1]: self.load_wsgi()
2019-02-09T19:37:48.242733+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2019-02-09T19:37:48.242735+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2019-02-09T19:37:48.242737+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2019-02-09T19:37:48.242738+00:00 app[web.1]: self.callable = self.load()
2019-02-09T19:37:48.242740+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2019-02-09T19:37:48.242741+00:00 app[web.1]: return self.load_wsgiapp()
2019-02-09T19:37:48.242743+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2019-02-09T19:37:48.242744+00:00 app[web.1]: return util.import_app(self.app_uri)
2019-02-09T19:37:48.242746+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
2019-02-09T19:37:48.242747+00:00 app[web.1]: __import__(module)
2019-02-09T19:37:48.242749+00:00 app[web.1]: File "/app/towima/towima/wsgi.py", line 16, in <module>
2019-02-09T19:37:48.242750+00:00 app[web.1]: application = get_wsgi_application()
2019-02-09T19:37:48.242751+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2019-02-09T19:37:48.242753+00:00 app[web.1]: django.setup(set_prefix=False)
2019-02-09T19:37:48.242754+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
2019-02-09T19:37:48.242756+00:00 app[web.1]: apps.populate(settings.INSTALLED_APPS)
2019-02-09T19:37:48.242757+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/apps/registry.py", line 89, in populate
2019-02-09T19:37:48.242759+00:00 app[web.1]: app_config = AppConfig.create(entry)
2019-02-09T19:37:48.242760+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/apps/config.py", line 90, in create
2019-02-09T19:37:48.242761+00:00 app[web.1]: module = import_module(entry)
2019-02-09T19:37:48.242763+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/importlib/__init__.py", line 127, in import_module
2019-02-09T19:37:48.242764+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2019-02-09T19:37:48.242766+00:00 app[web.1]: ModuleNotFoundError: No module named 'accounts'
2019-02-09T19:37:48.242921+00:00 app[web.1]: [2019-02-09 19:37:48 +0000] [11] [INFO] Worker exiting (pid: 11)
2019-02-09T19:37:48.266614+00:00 app[web.1]: [2019-02-09 19:37:48 +0000] [10] [ERROR] Exception in worker process
2019-02-09T19:37:48.266619+00:00 app[web.1]: Traceback (most recent call last):
2019-02-09T19:37:48.266621+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2019-02-09T19:37:48.266623+00:00 app[web.1]: worker.init_process()
2019-02-09T19:37:48.266625+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
2019-02-09T19:37:48.266627+00:00 app[web.1]: self.load_wsgi()
2019-02-09T19:37:48.266628+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2019-02-09T19:37:48.266630+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2019-02-09T19:37:48.266632+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2019-02-09T19:37:48.266634+00:00 app[web.1]: self.callable = self.load()
2019-02-09T19:37:48.266635+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2019-02-09T19:37:48.266637+00:00 app[web.1]: return self.load_wsgiapp()
2019-02-09T19:37:48.266639+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2019-02-09T19:37:48.266640+00:00 app[web.1]: return util.import_app(self.app_uri)
2019-02-09T19:37:48.266642+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
2019-02-09T19:37:48.266644+00:00 app[web.1]: __import__(module)
2019-02-09T19:37:48.266646+00:00 app[web.1]: File "/app/towima/towima/wsgi.py", line 16, in <module>
2019-02-09T19:37:48.266648+00:00 app[web.1]: application = get_wsgi_application()
2019-02-09T19:37:48.266649+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2019-02-09T19:37:48.266651+00:00 app[web.1]: django.setup(set_prefix=False)
2019-02-09T19:37:48.266653+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
2019-02-09T19:37:48.266654+00:00 app[web.1]: apps.populate(settings.INSTALLED_APPS)
2019-02-09T19:37:48.266656+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/apps/registry.py", line 89, in populate
2019-02-09T19:37:48.266657+00:00 app[web.1]: app_config = AppConfig.create(entry)
2019-02-09T19:37:48.266659+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/apps/config.py", line 90, in create
2019-02-09T19:37:48.266661+00:00 app[web.1]: module = import_module(entry)
2019-02-09T19:37:48.266662+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/importlib/__init__.py", line 127, in import_module
2019-02-09T19:37:48.266664+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2019-02-09T19:37:48.266666+00:00 app[web.1]: ModuleNotFoundError: No module named 'accounts'
2019-02-09T19:37:48.266819+00:00 app[web.1]: [2019-02-09 19:37:48 +0000] [10] [INFO] Worker exiting (pid: 10)
2019-02-09T19:37:48.401363+00:00 app[web.1]: [2019-02-09 19:37:48 +0000] [4] [INFO] Shutting down: Master
2019-02-09T19:37:48.401446+00:00 app[web.1]: [2019-02-09 19:37:48 +0000] [4] [INFO] Reason: Worker failed to boot.
2019-02-09T19:37:48.490323+00:00 heroku[web.1]: State changed from starting to crashed
2019-02-09T19:37:48.471230+00:00 heroku[web.1]: Process exited with status 3

如果有人可以帮助我,我将非常感激,因为我在这里失去了理智。预先谢谢你。

1 个答案:

答案 0 :(得分:0)

将顶层文件夹重命名为其他名称。

然后更改

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

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

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'towima.towima.settings')

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'towima.settings')