LoginSignup
1
4

More than 5 years have passed since last update.

タイトルの画像が表示されない Udemy 【3日でできる】はじめての Django 入門 レクチャー41

Posted at

はじめに

【3日でできる】はじめての Django 入門 ( Python 3 でウェブアプリを作って AWS EC2 で公開!)レクチャー41でタイトルの下に画像を表示しようとするも、表示されない。

結論

「settings.py」に問題があった。
※Q&Aに解決策が載っている

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [''],
        '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',
            ],
        },
    },
]

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['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',
            ],
        },
    },
]

『DIRS』に『'templates'』を入力する必要がある。

原因

テンプレートファイル側の

{% load static %}

が効いていない状態らしい。

その他確認事項

解決にあたり以下の項目の確認をしてくださいと先生が言っていた。

myblogapp直下のurls.pyでdjangoのstaticをインポートしているか?

from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static ←←←←←←←←←←←←←←←←←←←←
from django.conf import settings
from posts import views
'''

settings.pyで
1.staticfilesがINSTALLED_APPSにあるか

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles', ←←←←←←←←←←←←←←←←←←←←
'posts.apps.PostsConfig'
]
```

2.STATIC_URLが定義されているか

STATIC_URL = '/static/'
1
4
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
1
4