2015-09-25 129 views
1

我在Heroku上部署了簡單的博客應用程序,它在Django=1.8.4上運行,並且我遇到了一些問題白色靜態文件。不正確配置的靜態文件

當我打開我的應用程序時,我看到Application Error頁面,所以我嘗試調試它,發現當我提交給Heroku時,它不能對我的靜態文件夾執行靜音。其他的一切工作和Heroku上正顯示出我Build succeeded但不能瓶坯

remote: -----> Preparing static assets 
remote:  Collectstatic configuration error. To debug, run: 
remote:  $ heroku run python bloggy_project/manage.py collectstatic --noinput 

這樣的Heroku要我調試。當我鍵入

heroku run python bloggy_project/manage.py collectstatic --noinput 

錯誤日誌顯示:

Running python bloggy_project/manage.py collectstatic --noinput on greenbloggy... up, run.4682 
Traceback (most recent call last): 
    File "bloggy_project/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. 

是否嘗試過谷歌的答案,我現在非常困惑,因爲我已閱讀一堆關於靜態文件的職位。有人能告訴我什麼是錯誤的,所以我可以學習和理解一些東西。

礦settings.py:

""" 
Django settings for bloggy_project project. 

Generated by 'django-admin startproject' using Django 1.8.4. 

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

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

# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 
import os 

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

# Quick-start development settings - unsuitable for production 
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ 

# SECURITY WARNING: keep the secret key used in production secret! 
SECRET_KEY = 'oi1+cyk&9g-n*[email protected]!g7=edzpx+--rdsj4kw&4&3' 

# SECURITY WARNING: don't run with debug turned on in production! 
DEBUG = False 

ALLOWED_HOSTS = [] 


# Application definition 

INSTALLED_APPS = (
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    # Local Apps 
    'blog', 
    # Third party apps 
    'django_forms_bootstrap', 
) 

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', 
    'django.middleware.security.SecurityMiddleware', 
) 

ROOT_URLCONF = 'bloggy_project.urls' 

TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [os.path.join(BASE_DIR, '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 = 'bloggy_project.wsgi.application' 


# Database 
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases 

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.postgresql_psycopg2', 
     'NAME': '', 
     'USER': '', 
     'PASSWORD': '', 
     'HOST': '', 
     'POST': '', 
    } 
} 


# Internationalization 
# https://docs.djangoproject.com/en/1.8/topics/i18n/ 

LANGUAGE_CODE = 'en-us' 

TIME_ZONE = 'Europe/Belgrade' 

USE_I18N = True 

USE_L10N = True 

USE_TZ = True 


# Static files (CSS, JavaScript, Images) 
# https://docs.djangoproject.com/en/1.8/howto/static-files/ 
# Static asset configuration 
# Allow all host hosts/domain names for this site 
ALLOWED_HOSTS = ['*'] 

# Srse database configuration from $DATABASE_URL 
import dj_database_url 

DATABASES = {'default': dj_database_url.config()} 

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

# try to load development_settings.py if exists 
try: 
    from .development_settings import * 
except Exception, e: 
    pass 

import os 
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') 
MEDIA_URL = '/media/' 
# STATIC_ROOT = os.path.join(BASE_DIR, 'static') 
STATIC_URL = '/static/' 

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'), 
) 

UPDATE:

當我註釋掉STATIC_ROOT,並做

heroku run python bloggy_project/manage.py collectstatic --noinput 

錯誤日誌現在表明,這部分是依靠混亂的,爲什麼這個錯誤現在,如果我需要把STATIC_ROOT在我的settings.py

新的錯誤日誌:

Traceback (most recent call last): 
    File "bloggy_project/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/base.py", line 393, in run_from_argv 
    self.execute(*args, **cmd_options) 
    File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute 
    output = self.handle(*args, **options) 
    File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 168, in handle 
    collected = self.collect() 
    File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 97, in collect 
    for finder in get_finders(): 
    File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/finders.py", line 264, in get_finders 
    yield get_finder(finder_path) 
    File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/lru_cache.py", line 101, in wrapper 
    result = user_function(*args, **kwds) 
    File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/finders.py", line 277, in get_finder 
    return Finder() 
    File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/finders.py", line 66, in __init__ 
    "The STATICFILES_DIRS setting should " 
django.core.exceptions.ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting 
+1

錯誤指出發生了什麼問題:您尚未設置STATIC_ROOT。出於某種原因,您已在settings.py中設置它的位置註釋掉了該行。 –

+0

@DanielRoseman,我已經更新了我的問題,做過了,註釋掉了'STATIC_ROOT',但現在它顯示了另一個錯誤,而這部分依然讓我困惑,爲什麼現在這個錯誤呢? – PetarP

回答

8

你是因爲你設置的變量得到這個錯誤STATIC_ROOTSTATICFILES_DIRS包含完全相同的路徑(os.path.join(BASE_DIR, 'static'))。這是一個無效的配置。

STATIC_ROOT是您希望Django放置使用collectstatic收集的靜態文件的絕對路徑。您的Web服務器將從該目錄提供靜態文件。

STATICFILES_DIRS是您希望collectstatic在收集靜態文件時的樣子。如果不能包含STATIC_ROOT或其任何子目錄。

嘗試刪除STATICFILES_DIRS設置,看看是否有效。如果您已將靜態文件放入某個非標準位置,請更改設置以包含該位置。

+1

靜態文件夾是我的項目根目錄manage.py。這裏檢查[repository](https://github.com/Copser/BlogsterDj/tree/master/bloggy_project),不在家atm,但我會嘗試做你的建議和結果信息。 – PetarP

+1

我解決了一個靜態文件問題,需要在本地執行'./manage collectstatic',謝謝。 – PetarP