3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Wagtailチュートリアル 7 新しいページを追加しよう

Last updated at Posted at 2019-08-26

#Wagtailチュートリアル 6
<=6 Bootstrap4 を追加しよう
=>8 blocks.pyで新しいフィールドを作る(1)
##新しいページを追加しよう

python3 manage.py startapp flex
flexフォルダができる

16

wagtailtutorial/settings/base.py

.......
INSTALLED_APPS = [
    'home',
    'search',
    # 16 flexを追加
    'flex',

    'wagtail.contrib.forms',
    'wagtail.contrib.redirects',
    'wagtail.embeds',
    'wagtail.sites',
    'wagtail.users',
    'wagtail.snippets',
    'wagtail.documents',
    'wagtail.images',
    'wagtail.search',
    'wagtail.admin',
    'wagtail.core',

    'modelcluster',
    'taggit',

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
.......

16

flex/models.py
from django.db import models

# 16 モデルに必要なものをインポート
from wagtail.admin.edit_handlers import FieldPanel
from wagtail.core.models import Page

# 16 モデルを定義
class FlexPage(Page):

    template = "flex/flex_page.html"

    subtitle = models.CharField(max_length=100, null=True, blank=True)

    content_panels = Page.content_panels + [
        FieldPanel("subtitle"),
    ]

    class Meta:
        verbose_name = "Flex Page"
        verbose_name_plural = "Flex Pages"

17

wagtailtutorial/templates/flex/flex_page.html

{% extends "base.html" %}


{% block content %}
   {{self.subtitle}} is the subtitle {# 17 flexページのsubtitleを表示#}
{% endblock %}

16
スクリーンショット 2019-08-26 10.56.13.png

17
スクリーンショット 2019-08-26 11.02.41.png

3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?