首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Heroku部署Django应用程序时的错误

使用Heroku部署Django应用程序时的错误
EN

Stack Overflow用户
提问于 2015-07-20 10:01:36
回答 2查看 1K关注 0票数 1

我一直在尝试部署我的应用程序一整天,但没有运气。我遵循了这里上的步骤。我很难解释日志,所以我希望能在这里得到一些帮助。

settings.py

代码语言:javascript
复制
    """
Django settings for GingerEats project.

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

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


import os
import dj_database_url
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
ACTUAL_DIR = os.path.dirname(__file__)
TEMPLATE_PATH = os.path.join(ACTUAL_DIR, 'templates')
STATIC_PATH = os.path.join(ACTUAL_DIR, 'static')


SECRET_KEY = 'SECRET_KEY'


DEBUG = False

TEMPLATE_DEBUG = True

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    TEMPLATE_PATH,
)

ALLOWED_HOSTS = ['*']

# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'GingerBites'
)

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',
)

ROOT_URLCONF = 'GingerEats.urls'

WSGI_APPLICATION = 'GingerEats.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
import dj_database_url
DATABASES = {'default': dj_database_url.config()}
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'America/Los_Angeles'

USE_I18N = True

USE_L10N = True

USE_TZ = True




STATIC_URL = '/static/'

STATICFILES_DIRS = (
    STATIC_PATH,
)

Procfile

代码语言:javascript
复制
web: gunicorn GingerEats.wsgi --log-file -

requirements.txt

代码语言:javascript
复制
beautifulsoup4==4.4.0
dateutils==0.6.6
dj-database-url==0.3.0
dj-static==0.0.6
Django==1.8.3
django-toolbelt==0.0.1
gunicorn==19.3.0
Pillow==2.9.0
psycopg2==2.6.1
python-dateutil==2.4.2
pytz==2015.4
six==1.9.0
static3==0.6.1
wheel==0.24.0

来自app助手文件

代码语言:javascript
复制
from bs4 import BeautifulSoup

heroku日志

代码语言:javascript
复制
2015-07-20T09:48:46.585197+00:00 heroku[slug-compiler]: Slug compilation started
2015-07-20T09:48:46.585221+00:00 heroku[slug-compiler]: Slug compilation finished
2015-07-20T09:48:46.632808+00:00 heroku[web.1]: State changed from up to starting
2015-07-20T09:48:49.329911+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2015-07-20T09:48:50.033795+00:00 app[web.1]: [2015-07-20 02:48:50 +0000] [10] [INFO] Worker exiting (pid: 10)
2015-07-20T09:48:50.063556+00:00 app[web.1]: [2015-07-20 09:48:50 +0000] [3] [INFO] Shutting down: Master
2015-07-20T09:48:50.019993+00:00 app[web.1]: [2015-07-20 02:48:50 +0000] [9] [INFO] Worker exiting (pid: 9)
2015-07-20T09:48:50.040626+00:00 app[web.1]: [2015-07-20 09:48:50 +0000] [3] [INFO] Handling signal: term
2015-07-20T09:48:50.370142+00:00 heroku[web.1]: Starting process with command `gunicorn GingerEats.wsgi --log-file -`
2015-07-20T09:48:50.947622+00:00 heroku[web.1]: Process exited with status 0
2015-07-20T09:48:53.132305+00:00 heroku[web.1]: State changed from starting to up
2015-07-20T09:48:53.036580+00:00 app[web.1]: [2015-07-20 09:48:53 +0000] [3] [INFO] Starting gunicorn 19.3.0
2015-07-20T09:48:53.043597+00:00 app[web.1]: [2015-07-20 09:48:53 +0000] [3] [INFO] Using worker: sync
2015-07-20T09:48:53.158484+00:00 app[web.1]: [2015-07-20 09:48:53 +0000] [10] [INFO] Booting worker with pid: 10
2015-07-20T09:48:53.037329+00:00 app[web.1]: [2015-07-20 09:48:53 +0000] [3] [INFO] Listening at: http://0.0.0.0:16584 (3)
2015-07-20T09:48:53.074698+00:00 app[web.1]: [2015-07-20 09:48:53 +0000] [9] [INFO] Booting worker with pid: 9
2015-07-20T09:48:56.052969+00:00 heroku[router]: at=info method=GET path="/" host=young-river-3159.herokuapp.com request_id=7bbae61c-1677-443e-a661-e5e49c8298fd fwd="73.189.127.134" dyno=web.1 connect=1ms service=475ms status=500 bytes=239
2015-07-20T09:55:45.893669+00:00 heroku[router]: at=info method=GET path="/" host=young-river-3159.herokuapp.com request_id=fa2f81a3-fa90-41c3-87f5-d1e7b0402fe9 fwd="73.189.127.134" dyno=web.1 connect=3ms service=32ms status=500 bytes=239
2015-07-20T09:57:53.360261+00:00 heroku[api]: Starting process with command `python manage.py collectstatic --noinput` by 
2015-07-20T09:57:58.504151+00:00 heroku[run.9993]: Awaiting client
2015-07-20T09:57:58.545153+00:00 heroku[run.9993]: Starting process with command `python manage.py collectstatic --noinput`
2015-07-20T09:57:58.884863+00:00 heroku[run.9993]: State changed from starting to up
2015-07-20T09:58:01.531091+00:00 heroku[run.9993]: State changed from up to complete
2015-07-20T09:58:01.516810+00:00 heroku[run.9993]: Process exited with status 1
2015-07-20T10:05:23.378880+00:00 heroku[slug-compiler]: Slug compilation started
2015-07-20T10:05:23.378899+00:00 heroku[slug-compiler]: Slug compilation finished
2015-07-20T10:05:23.321985+00:00 heroku[api]: Deploy 36e0a00 by me@gmail.com
2015-07-20T10:05:23.321985+00:00 heroku[api]: Release v23 created by me@gmail.com
2015-07-20T10:05:23.484287+00:00 heroku[web.1]: State changed from up to starting
2015-07-20T10:05:26.662103+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2015-07-20T10:05:27.376506+00:00 app[web.1]: [2015-07-20 10:05:27 +0000] [3] [INFO] Handling signal: term
2015-07-20T10:05:27.377900+00:00 app[web.1]: [2015-07-20 03:05:27 +0000] [9] [INFO] Worker exiting (pid: 9)
2015-07-20T10:05:27.377911+00:00 app[web.1]: [2015-07-20 03:05:27 +0000] [10] [INFO] Worker exiting (pid: 10)
2015-07-20T10:05:27.795568+00:00 app[web.1]: [2015-07-20 10:05:27 +0000] [3] [INFO] Shutting down: Master
2015-07-20T10:05:28.751407+00:00 heroku[web.1]: Process exited with status 0
2015-07-20T10:05:35.131870+00:00 heroku[web.1]: Starting process with command `gunicorn GingerEats.wsgi --log-file -`
2015-07-20T10:05:38.259027+00:00 app[web.1]: [2015-07-20 10:05:38 +0000] [3] [INFO] Listening at: http://0.0.0.0:13138 (3)
2015-07-20T10:05:38.259151+00:00 app[web.1]: [2015-07-20 10:05:38 +0000] [3] [INFO] Using worker: sync
2015-07-20T10:05:38.281227+00:00 app[web.1]: [2015-07-20 10:05:38 +0000] [9] [INFO] Booting worker with pid: 9
2015-07-20T10:05:38.258301+00:00 app[web.1]: [2015-07-20 10:05:38 +0000] [3] [INFO] Starting gunicorn 19.3.0
2015-07-20T10:05:38.311885+00:00 app[web.1]: [2015-07-20 10:05:38 +0000] [10] [INFO] Booting worker with pid: 10
2015-07-20T10:05:39.141716+00:00 heroku[web.1]: State changed from starting to up
2015-07-20T10:05:48.344166+00:00 heroku[router]: at=info method=GET path="/" host=young-river-3159.herokuapp.com request_id=5ca6f7b1-fc15-45e1-9cd5-6d25e6f1c7f2 fwd="73.189.127.134" dyno=web.1 connect=0ms service=274ms status=500 bytes=239


**Actual push to heroku**

    git push heroku master
    Counting objects: 4, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (4/4), done.
    Writing objects: 100% (4/4), 357 bytes | 0 bytes/s, done.
    Total 4 (delta 3), reused 0 (delta 0)
    remote: Compressing source files... done.
    remote: Building source:
    remote: 
    remote: -----> Removing .DS_Store files
    remote: -----> Python app detected
    remote: -----> Installing dependencies with pip
    remote: You are using pip version 7.0.3, however version 7.1.0 is available.
    remote: You should consider upgrading via the 'pip install --upgrade pip' command.
    remote: 
    remote: -----> Preparing static assets
    remote:        Collectstatic configuration error. To debug, run:
    remote:        $ heroku run python manage.py collectstatic --noinput
    remote: 
    remote: -----> Discovering process types
    remote:        Procfile declares types -> web
    remote: 
    remote: -----> Compressing... done, 37.9MB
    remote: -----> Launching... done, v22
    remote:        https://young-river-3159.herokuapp.com/ deployed to Heroku
    remote: 
    remote:  !   Cedar-10 will reach end-of-life on November 4th, 2015.
    remote:  !   Upgrade to Cedar-14 at your earliest convenience.
    remote:  !   For more information, check out the following Dev Center article:
    remote:  !   https://devcenter.heroku.com/articles/cedar-14-migration
    remote: 
    remote: Verifying deploy.... done.
    To https://git.heroku.com/young-river-3159.git
       0e95162..4bc34e8  master -> master

**Static Assets debug**
    heroku run python manage.py collectstatic --noinput

    Running `python manage.py collectstatic --noinput` attached to terminal... up, run.9993
    Traceback (most recent call last):
      File "manage.py", line 10, in <module>
        execute_from_command_line(sys.argv)
      File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
        utility.execute()
      File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 190, in fetch_command
        klass = load_command_class(app_name, subcommand)
      File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 41, in load_command_class
        return module.Command()
      File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 32, in __init__
        self.storage.path('')
      File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py", line 48, in path
        raise ImproperlyConfigured("You're using the staticfiles app "
    django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.

Any help would be so much appreciated. This has been so difficult to overcome. Procfile and requirements.txt are in root directory. This all results in a 
Server Error (500).
EN

回答 2

Stack Overflow用户

发布于 2015-07-20 10:22:12

您获得的错误日志很好地描述了这个问题:

...ImproperlyConfigured:您使用的是静态文件应用程序,而没有将STATIC_ROOT设置设置为文件系统路径。

您正在作为部署的一部分运行manage.py collectstatic命令。这应该从您的各种STATICFILES_DIRS中收集所有静态文件,并将它们放在一个文件夹中:STATIC_ROOT,用于您的them服务器(Apache或Nginx)来服务它们。

您需要为STATIC_ROOT选择一个文件夹,以便collectstatic可以根据这里的文件将静态文件放入该文件夹。

您还必须确保静态文件目录配置正确,并且您的the服务器正在正确地调用它们,但上述问题是当前问题的症结所在。

票数 2
EN

Stack Overflow用户

发布于 2019-03-14 19:28:37

好吧,您正在使用调试模式false。发生此错误是因为您没有正确设置应用程序的静态文件目录。在您的settings.py中粘贴下面的代码。

代码语言:javascript
复制
#default static url
STATIC_URL = '/static/'

#this when debug is True, the project should look where static folder located, set STATICFILES_DIRS accordingly:
if DEBUG:
   STATICFILES_DIRS = [
   os.path.join(BASE_DIR, 'static'),
   ]
#when you change environemnt to production, STATIC_ROOT should be given. 
else:
   STATIC_ROOT = os.path.join(BASE_DIR,'static')

#for media files add followings:
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31513629

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档