ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 3. Wagtail CMS의 첫 홈 페이지 시작하기
    파이썬/Wagtail 2021. 2. 11. 14:17

    참고 영상 : www.youtube.com/watch?v=SEPBP0DuoWg&list=PLMQHMcNi6ocsS8Bfnuy_IDgJ4bHRRrvub&index=2

     

    조작할 파일은 home_page.html, models.py

    home_page.html

    1
    2
    3
    {% block content %}
        Hello World
    {% endblock %}
    cs

     

    models.py

    1
    2
    3
    4
    5
    6
    7
    8
    9
    from django.db import models
     
    from wagtail.core.models import Page
     
     
    class HomePage(Page):
        """Home page model."""
        templates = "home/home_page.html"
        pass
    cs

     

    결과 (localhost:8000)


    models.py

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    from django.db import models
    from wagtail.admin.edit_handlers import FieldPanel
    from wagtail.core.models import Page
    class HomePage(Page):
        """Home page model."""
        templates = "home/home_page.html"
        banner_title = models.CharField(max_length=100, blank=Truenull=True)
        content_panels = Page.content_panels +[
            FieldPanel("banner_title")
        ]
        pass
     
    cs

     

    models.py에 데이터 베이스 필드를 추가할 경우 하기의 명령을 실행하여 테이블을 업데이트 해주어야 한다.

     

    마이그레이션 파일 생성

    python manage.py makemigrations

     

    마이그레이션 적용

    python manage.py migrate

     

    관리자 페이지(http://localhost:8000/admin)로 접속하여 Page -> Page로 이동

    Banner Title이 추가된 것을 확인할 수 있다.

    Hello This is Banner Title 을 입력하고 PUBLISH한다

     

    home_page.html

    1
    2
    3
    {% block content %}
        {{ self.banner_title }}
    {% endblock %}
    cs

     

    결과 (localhost:8000)


    models.py에 Meta 옵션을 추가한다.
    Meta 옵션이란 다음과 같이 Inner class로 사용하여 상위 클래스에게 meta data를 제공하는것이다.

    models.py

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    from django.db import models
    from wagtail.admin.edit_handlers import FieldPanel
     
    from wagtail.core.models import Page
     
     
    class HomePage(Page):
        """Home page model."""
        templates = "home/home_page.html"
        banner_title = models.CharField(max_length=100, blank=Truenull=True)
        content_panels = Page.content_panels + [
            FieldPanel("banner_title")
        ]
     
        class Meta:
            verbose_name = "OH HELLO WORLD"
            verbose_name_plural = "PLURAL NAME"
     
    cs

     

    ADD CHILD PAGE로 들어가보면 변경된 것을 확인할 수 있다.

     

     

    '파이썬 > Wagtail' 카테고리의 다른 글

    2. Pipenv를 사용하여 6 분 이내에 Wagtail CMS 설치하기  (0) 2021.02.11
    1 . Wagtail이란?  (0) 2021.02.11

    댓글

Designed by Tistory.