2017-09-24 1 views
0

장고를 배우고 샘플 장고 앱을 만들었습니다. 내 컴퓨터에서 제대로 작동하지만 Heroku에 배포하는 데 문제가 있습니다. 내 루트 디렉토리의 구조는 다음과 같습니다장고의 STATIC_ROOT 설정

STATIC_URL = '/static/' 
STATICFILES_DIRS = [ 
os.path.join(BASE_DIR, "static") 
] 
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') 
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage' 

전체 settings.py 파일이 다음입니다 :

내 setttings.py 파일이 정적 파일에 대해 다음과 같은 설정을 가지고

Second screen

First screen

""" 
Django settings for firstdjango project. 

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

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 = 'j8s(6fw61+cx_o=g!9a(vs!wbj0&f!7u_lw$([email protected]!b4(' 

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

ALLOWED_HOSTS = [] 


# Application definition 

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

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 = 'firstdjango.urls' 

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


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

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


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

LANGUAGE_CODE = 'en-us' 

TIME_ZONE = 'UTC' 

USE_I18N = True 

USE_L10N = True 

USE_TZ = True 


# Static files (CSS, JavaScript, Images) 
# https://docs.djangoproject.com/en/1.8/howto/static-files/ 

import dj_database_url 
db_from_env = dj_database_url.config(conn_max_age = 500) 
DATABASES['default'].update(db_from_env) 

# STATIC_URL = '/static/' 
# STATICFILES_DIRS = [ 
# os.path.join(BASE_DIR, "static") 
# ] 
# STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') 

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') 
STATIC_URL = '/static/'  

# Extra places for collectstatic to find static files. 
STATICFILES_DIRS = [ 
    os.path.join(BASE_DIR, 'static'), 
] 
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage' 

헤로 쿠에 배포하려고하면 다음과 같은 메시지가 표시됩니다. 오류 메시지 :

ImproperlyConfigured : 당신은 파일 시스템 경로 여기

+0

@ user1787331 괜찮습니다.하지만 장고에서 정적 파일을 설정하는 올바른 방법과 제가 누락 된 부분을 알고 싶습니다. –

+0

답변에 대한 내 의견을 이동했습니다. – user1787331

+0

나머지 설정 파일을 표시하십시오. –

답변

0

에 STATIC_ROOT 설정을 설정하지 않고 staticfiles 앱을 사용하는 장고 정적 루트에 권장되는 설정입니다 -> Heroku가 프로젝트

# Static files (CSS, JavaScript, Images) 
# https://docs.djangoproject.com/en/1.11/howto/static-files/  

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles') 
STATIC_URL = '/static/'  

# Extra places for collectstatic to find static files. 
STATICFILES_DIRS = [ 
    os.path.join(PROJECT_ROOT, 'static'), 
] 

이을 시작점으로 사용하고 앱을 해당 프로젝트로 가져 오는 것이 좋습니다. 때문에 Heroku가이

Gunicorn 
WhiteNoise 
dj-database-url 

이 망할 놈의 프로젝트는 "정적 파일, 데이터베이스 설정, Gunicorn, 등 생산 준비 구성"을 제공합니다 다음과 같은 패키지를 사용하는 것이 좋습니다 것을 (지금 현재) 사실 즉, Django를 Heroku에 배포하기위한 올바른 구성을 제공합니다.

관련 문제