LoginSignup
2
3

More than 5 years have passed since last update.

Django備忘録~settings.py~

Last updated at Posted at 2018-05-27

環境:Django2, Python3.6

プロジェクト共通のstatic/templatesディレクトリ

templates

デフォルトでテンプレートの設定はあるはずなので、それのDIRSに追加
私はプロジェクト共通のbase.htmlとかを置いてます。
APP_DIRSがTrueの場合は各アプリの直下にあるtemplatesディレクトリも探しに行ってくれます。

settings.py
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',
            ],
        },
    },
]

static

デフォルトだと記述されてないので追記する
Bootstrapをプロジェクト全体で使うときとか共通のcss/jsはここに置いてます。

settings.py
STATICFILES_DIRS = (
    [os.path.join(BASE_DIR, 'static')]
)
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3