2017-09-24 17 views
0

私はDjangoを学んでおり、サンプルのDjangoアプリを構築しました。それは私のコンピュータ上で正常に動作しますが、私はHerokuにそれを配備するのに問題があります。 私のルートディレクトリには、以下の構造を有する: First screenDjangoのSTATIC_ROOT設定

Second screen

は私のsetttings.pyファイルには、静的ファイルの以下の設定があります。

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ファイルは以下の通りです:

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

私がHerokuに展開しようとすると、次のようになりますエラーメッセージ:

ImproperlyConfigured:あなたはファイルシステムのパスここ

+0

@ user1787331大丈夫ですが、私はDjangoで静的ファイルを設定する正しい方法と、私が紛失しているものを知りたいと思います。 –

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

私はちょうどこのhttps://github.com/heroku/heroku-django-templateを出発点として使用して、そのプロジェクトにあなたのアプリケーションをインポートすることをお勧めします。原因Herokuのは

Gunicorn 
WhiteNoise 
dj-database-url 

はgitのプロジェクトは、「静的ファイル、データベース設定、Gunicornなどの生産対応の構成」を提供します以下のパッケージを使用することをお勧めしていること(今のような)事実につまり、DjangoをHerokuにデプロイするための正しい設定ができます。

関連する問題