Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django应用程序部署到Heroku,应用程序错误,_Python_Django_Heroku - Fatal编程技术网

Python Django应用程序部署到Heroku,应用程序错误,

Python Django应用程序部署到Heroku,应用程序错误,,python,django,heroku,Python,Django,Heroku,我正在努力将我的Django 1.10应用程序部署到Heroku。作为前言,我正在使用Pycharm,曾一度不得不重命名我的项目,但它在所有地方都进行了重构并更改了名称,所以我希望这与问题无关。当我把这个网站推到Heroku时,我得到一个应用程序错误 错误消息 在Heroku应用程序错误日志中,我看到: 2017-01-13T22:04:48.911324+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET

我正在努力将我的Django 1.10应用程序部署到Heroku。作为前言,我正在使用Pycharm,曾一度不得不重命名我的项目,但它在所有地方都进行了重构并更改了名称,所以我希望这与问题无关。当我把这个网站推到Heroku时,我得到一个应用程序错误

错误消息

在Heroku应用程序错误日志中,我看到:

2017-01-13T22:04:48.911324+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=secret-anchorage-68558.herokuapp.com request_id=71351a21-2264-4ca7-ad0a-1ae110d72ca7 fwd="162.247.89.174" dyno= connect= service= status=503 bytes=
2017-01-13T22:04:49.334411+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=secret-anchorage-68558.herokuapp.com request_id=bf22a256-8780-49ed-8820-c8112833121c fwd="162.247.89.174" dyno= connect= service= status=503 bytes=
它曾经在我的计算机上本地工作,但现在当我尝试运行应用程序时,我得到:

python3 manage.py runserver

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f278bc6ea60>
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/commands/runserver.py", line 113, in inner_run
autoreload.raise_last_exception()
File "/usr/local/lib/python3.5/dist-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/usr/local/lib/python3.5/dist-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/usr/local/lib/python3.5/dist-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.5/dist-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python3.5/dist-packages/django/apps/config.py", line 116, in create
mod = import_module(mod_path)
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'homelibrary.apps'
这似乎很有希望。它允许我将代码推送到Heroku,但是当我尝试

heroku run python3 manage.py migrate

我得到了和以前一样的错误,它不会出现在网上

项目结构

---homelibrary
   ---catalog
      ---migrations
      ---static
         ---css
         ---images
            favicon.ico
      ---templates
      __init__.py
      admin.py
      apps.py
      forms.py
      models.py
      tests.py
      urls.py
      views.py
   ---homelibrary
      __init__.py
      settings.py
      urls.py
      wsgi.py
  ---templates (for generic, cross-site forms)
  ---venv
  .gitignore.txt
  db.sqlite3
  LICENSE
  manage.py
  Procfile
  README.md
  requirements.txt
  runtime.txt
web: gunicorn homelibrary.wsgi --log-file -
Requirements.txt

dj-database-url==0.4.2
Django==1.10.5
gunicorn==19.6.0
psycopg2==2.6.2
whitenoise==3.2.3
Procfile

---homelibrary
   ---catalog
      ---migrations
      ---static
         ---css
         ---images
            favicon.ico
      ---templates
      __init__.py
      admin.py
      apps.py
      forms.py
      models.py
      tests.py
      urls.py
      views.py
   ---homelibrary
      __init__.py
      settings.py
      urls.py
      wsgi.py
  ---templates (for generic, cross-site forms)
  ---venv
  .gitignore.txt
  db.sqlite3
  LICENSE
  manage.py
  Procfile
  README.md
  requirements.txt
  runtime.txt
web: gunicorn homelibrary.wsgi --log-file -
家庭图书馆/wsgi.py

import os

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

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "homelibrary.settings")

application = get_wsgi_application()
application = DjangoWhiteNoise(application)
import os
import dj_database_url

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'My key')

DEBUG = bool(os.environ.get('DJANGO_DEBUG', False))

ALLOWED_HOSTS = []

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'homelibrary.apps.CatalogConfig',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'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 = 'homelibrary.urls'

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': ['./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',
        ],
    },
},
]

WSGI_APPLICATION = 'homelibrary.wsgi.application'

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

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',
},
homelibrary/settings.py

import os

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

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "homelibrary.settings")

application = get_wsgi_application()
application = DjangoWhiteNoise(application)
import os
import dj_database_url

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'My key')

DEBUG = bool(os.environ.get('DJANGO_DEBUG', False))

ALLOWED_HOSTS = []

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'homelibrary.apps.CatalogConfig',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'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 = 'homelibrary.urls'

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': ['./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',
        ],
    },
},
]

WSGI_APPLICATION = 'homelibrary.wsgi.application'

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

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',
},
]


你知道我做错了什么吗?

只要用这个更改你的
安装的应用程序

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'catalog',
]
之后你会面临更多的错误

  • 如果生产中的
    DEBUG
    设置为
    False
    ,则需要更改
    ALLOWED\u HOSTS=[]
    允许的\u主机=['*']

  • 加载项
    settings.py
    文件

    STATICFILES\u STORAGE='whitenoise.django.gzip静态文件存储'


  • 如果它不起作用,那么再做一件事,看看第8步和第9步

    谢谢,这对解决静态文件问题很有帮助。我有一个类似的问题,但这里的解决方案对我来说并不适用。你能帮我看看吗?