2015-07-20 181 views
1

我一直试图部署我的应用程序整天,但没有运气。我遵循here的步骤。我很难解释日志,所以我希望能在这里得到一些帮助。使用Heroku在Django应用程序中部署的错误

settings.py

""" 
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

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

requirements.txt

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 

从应用程序的辅助文件

from bs4 import BeautifulSoup 

Heroku的日志

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 [email protected] 
2015-07-20T10:05:23.321985+00:00 heroku[api]: Release v23 created by [email protected] 
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). 

回答

2

错误日志中你得到了有关问题的一个很好的说明:

... ImproperlyConfigured:您正在使用staticfiles应用程序,而未将STATIC_ROOT设置设置为文件系统路径。

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

您需要为STATIC_ROOT选择一个文件夹,以便collectstatic可以将您的静态文件放到该文件夹​​中,每个documentation here

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