1. Start Site and Alter Home Page

Wagtail changes so much about how Django works, it is recommended you start a complete new project with it.

Install wagail normally using pip install wagtail

Start a project with wagtail start mysite mysite

Install the requirements with pip install -r requirements.txt

migrate the database with python manage.py migrate

create a user python manage.py createsuperuser

Untitled

Your folder structure will look like this, starting out with ‘home’ and ‘search’.

from django.db import models

from wagtail.models import Page

class HomePage(Page):
    pass

Wagtail changes how views in general works, now they are “Pages” and they reside in models.py in your apps folder.

Content Panels allow you to show your django fields to your page.

from django.db import models
from wagtail.admin.panels import FieldPanel

from wagtail.models import Page

class HomePage(Page):
    """Home Page Model"""
    # without naming a template, wagtail looks for a base one
    templates = "home/home_page.html"
    # cannot be blank when submitted, but it can be null in the database
    banner_title = models.CharField(max_length=100, blank=False, null=True)

    content_panels = Page.content_panels + [
        FieldPanel("banner_title")
    ]

Untitled

This leads to an error because we are yet to migrate. Migrating will fix this.

Untitled

This banner title will now show up in the admin page, allowing admins to change the page at will.

Now we have to tell our template to take this field into account.

{% block content %} # content is extented from base.html
    {{ self.banner_title }}
{% endblock %}

The admin page lets you do a lot of things you would normally have to do in the terminal with vanilla django, like create a child page: