Add Wagtail to Django
If you have a website with Django you can easily add Wagtail to it.
Just follow this simple steps.
Installation
Wagtail and wagtailmedia
pip install wagtail wagtailmedia
Birdapp657
If you want to use a ready to use wagtail app you can install the basic wagtail app Birdapp657.
pip install git+https://github.com/oscfr657/birdapp657.git@main
Django settings
To your settings file,
add to the INSTALLED_APPS
'django.contrib.sites', # Extra for Birdapp657
'django.contrib.sitemaps', # Extra for Birdapp657
# wagtail
'wagtail.contrib.forms',
'wagtail.contrib.redirects',
'wagtail.contrib.settings', # Extra for Birdapp657
'wagtail.contrib.search_promotions', # Extra for Birdapp657
'wagtail.embeds',
'wagtail.sites',
'wagtail.users',
'wagtail.snippets',
'wagtail.documents',
'wagtail.images',
'wagtail.search',
'wagtail.admin',
'wagtail.core',
'modelcluster',
'taggit',
# birdapp657 default search backend
'wagtail.contrib.postgres_search',
# birdapp657 media file block
'wagtailmedia',
# Birdapp657
'birdapp657',
add to the MIDDLEWARE settings
'django.contrib.sites.middleware.CurrentSiteMiddleware',
'wagtail.contrib.redirects.middleware.RedirectMiddleware',
add to the TEMPLATES settings
TEMPLATES = [
{
'OPTIONS': {
'context_processors': [
'wagtail.contrib.settings.context_processors.settings', # Birdapp657
},
},
]
I recommend
set the
WAGTAILIMAGES_FORMAT_
CONVERSIONS
setting:
WAGTAILIMAGES_FORMAT_CONVERSIONS = {
'bmp': 'webp',
'jpeg': 'webp',
'jpg': 'webp',
'JPG': 'webp',
'webp': 'webp',
'png': 'webp',
}
Django url
To the django projects' url.py add
from django.urls import path, re_path
from django.conf.urls import include
# Wagtail
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.documents import urls as wagtaildocs_urls
from wagtail.core import urls as wagtail_urls
from wagtail.contrib.sitemaps.views import sitemap
and
urlpatterns = [
re_path('sitemap.xml', sitemap),
# Wagtail
re_path(r'^birdapp/', include(wagtailadmin_urls)),
re_path(r'^documents/', include(wagtaildocs_urls)),
re_path(r'', include(wagtail_urls)),
]
optionally
handler403 = 'birdapp657.views.bird_page_403'
handler404 = 'birdapp657.views.bird_page_404'
handler500 = 'birdapp657.views.bird_page_500'
Database setup
python manage.py migrate
Search Index setup
python manage.py update_index
Collectstatic
python manage.py collectstatic