### live() method example Source: https://docs.wagtail.org/en/stable/reference/pages/queryset_reference.html Example demonstrating the use of the `live()` method to get published pages. ```python published_pages = Page.objects.live() ``` -------------------------------- ### Site-specific settings example Source: https://docs.wagtail.org/en/stable/advanced_topics/multi_site_multi_instance_multi_tenancy.html Example of how to configure site-specific settings for a multi-instance setup, overriding base settings. ```python from base import * # noqa ALLOWED_HOSTS = ['a.com'] DATABASES["NAME"] = "acom" DATABASES["PASSWORD"] = "password-for-acom" MEDIA_DIR = BASE_DIR / "acom-media" ``` -------------------------------- ### Project setup steps Source: https://docs.wagtail.org/en/stable/getting_started/quick_install.html Installs project requirements, applies database migrations, creates a superuser, and runs the development server. ```sh pip install -r requirements.txt python manage.py migrate python manage.py createsuperuser python manage.py runserver ``` -------------------------------- ### Start a new Wagtail project Source: https://docs.wagtail.org/en/stable/getting_started/quick_install.html Generates a new Wagtail project named 'mysite'. ```sh wagtail start mysite ``` -------------------------------- ### BlogPage model example Source: https://docs.wagtail.org/en/stable/advanced_topics/api/v2/configuration.html Example of configuring API fields for a BlogPage model, including a related Orderable model. ```python from wagtail.api import APIField class BlogPageAuthor(Orderable): page = models.ForeignKey('blog.BlogPage', on_delete=models.CASCADE, related_name='authors') name = models.CharField(max_length=255) api_fields = [ APIField('name'), ] class BlogPage(Page): published_date = models.DateTimeField() body = RichTextField() feed_image = models.ForeignKey('wagtailimages.Image', on_delete=models.SET_NULL, null=True, ...) private_field = models.CharField(max_length=255) # Export fields over the API api_fields = [ APIField('published_date'), APIField('body'), APIField('feed_image'), APIField('authors'), # This will nest the relevant BlogPageAuthor objects in the API response ] ``` -------------------------------- ### Pagination example Source: https://docs.wagtail.org/en/stable/advanced_topics/api/v2/usage.html Demonstrates how to use the `?limit` and `?offset` parameters to control the number of items returned and skip items. ```http GET /api/v2/pages/?offset=20&limit=20 HTTP 200 OK Content-Type: application/json { "meta": { "total_count": 50 }, "items": [ pages 20 - 40 will be listed here. ] } ``` -------------------------------- ### API Authentication with TokenAuthentication Source: https://docs.wagtail.org/en/stable/advanced_topics/api/v2/configuration.html Example of setting up Token Authentication for the Wagtail API. ```python # api.py from rest_framework.permissions import IsAuthenticated # ... class CustomPagesAPIViewSet(PagesAPIViewSet): name = "pages" permission_classes = (IsAuthenticated,) api_router.register_endpoint("pages", CustomPagesAPIViewSet) ``` ```python # settings.py INSTALLED_APPS = [ ... 'rest_framework.authtoken', ... ] ... REST_FRAMEWORK = { "DEFAULT_AUTHENTICATION_CLASSES": [ "rest_framework.authentication.TokenAuthentication" ], } ``` -------------------------------- ### Homepage redirect example Source: https://docs.wagtail.org/en/stable/advanced_topics/api/v2/usage.html Example of finding the homepage by its HTML path. ```http /api/v2/pages/find/?html_path=/ ``` -------------------------------- ### not_live() method example Source: https://docs.wagtail.org/en/stable/reference/pages/queryset_reference.html Example demonstrating the use of the `not_live()` method to get unpublished pages. ```python unpublished_pages = Page.objects.not_live() ``` -------------------------------- ### Install the styleguide module Source: https://docs.wagtail.org/en/stable/contributing/ui_guidelines.html Add the wagtail.contrib.styleguide module to INSTALLED_APPS to enable the UI styleguide. ```python INSTALLED_APPS = ( # ... 'wagtail.contrib.styleguide', # ... ) ``` -------------------------------- ### ImageRenditionField filter specifications examples Source: https://docs.wagtail.org/en/stable/advanced_topics/api/v2/configuration.html Examples of common filter specifications for ImageRenditionField. ```python # Square crop and fill APIField('thumbnail', serializer=ImageRenditionField('fill-300x300', source='image')) # Maintain aspect ratio with maximum dimensions APIField('preview', serializer=ImageRenditionField('max-800x600', source='image')) # Exact dimensions without cropping APIField('banner', serializer=ImageRenditionField('width-1200', source='image')) # Chained operations (multiple filters combined) APIField('compressed_thumb', serializer=ImageRenditionField('fill-200x200|jpegquality-60', source='image')) ``` -------------------------------- ### Run all formatting Source: https://docs.wagtail.org/en/stable/contributing/first_contribution_guide.html Command to run all code formatting using pre-commit. ```bash make format ``` -------------------------------- ### Contributor Checklist (Default) - Development Environment Setup Source: https://docs.wagtail.org/en/stable/contributing/first_contribution_guide.html A checklist for setting up the development environment. ```default - [ ] Install `git` (if not on your machine). - [ ] Install a code editor/IDE (we recommend VSCode). - [ ] Install the dependencies set out in the development guide. - [ ] Follow the development guide. - [ ] Make a change to the `wagtail/admin/templates/wagtailadmin/home.html` template file and confirm you can see the changes on the Wagtail dashboard (home) page. - [ ] Add a `console.log` statement to `client/src/entrypoints/admin/wagtailadmin.js` and confirm you can see the logging in the browser. ``` -------------------------------- ### sibling_of() method example Source: https://docs.wagtail.org/en/stable/reference/pages/queryset_reference.html Example demonstrating the use of `sibling_of()` to get pages that are siblings of a specified page. ```python # Get list of siblings siblings = Page.objects.sibling_of(current_page) # Alternative way siblings = current_page.get_siblings() ``` -------------------------------- ### ancestor_of() method example Source: https://docs.wagtail.org/en/stable/reference/pages/queryset_reference.html Example demonstrating the use of `ancestor_of()` to get pages that are ancestors of a specified page. ```python # Get the current section current_section = Page.objects.ancestor_of(current_page).child_of(homepage).first() # Alternative way current_section = current_page.get_ancestors().child_of(homepage).first() ``` -------------------------------- ### Start the server Source: https://docs.wagtail.org/en/stable/getting_started/tutorial.html Command to start the Wagtail development server. ```sh python manage.py runserver ``` -------------------------------- ### child_of() method example Source: https://docs.wagtail.org/en/stable/reference/pages/queryset_reference.html Example demonstrating the use of `child_of()` to get direct children of a specified page. ```python # Get a list of sections sections = Page.objects.child_of(homepage) # Alternative way sections = homepage.get_children() ``` -------------------------------- ### descendant_of() method example Source: https://docs.wagtail.org/en/stable/reference/pages/queryset_reference.html Example demonstrating the use of `descendant_of()` to get pages that descend from a specified page. ```python # Get EventPages that are under the special_events Page special_events = EventPage.objects.descendant_of(special_events_index) # Alternative way special_events = special_events_index.get_descendants() ``` -------------------------------- ### Install wagtail.contrib.settings Source: https://docs.wagtail.org/en/stable/tutorial/create_footer_for_all_pages.html Adds 'wagtail.contrib.settings' to the INSTALLED_APPS list in settings.py. ```python INSTALLED_APPS = [ # ... # Add this line to install wagtail.contrib.settings: "wagtail.contrib.settings", ] ``` -------------------------------- ### in_menu() method example Source: https://docs.wagtail.org/en/stable/reference/pages/queryset_reference.html Example demonstrating the use of the `in_menu()` method to get pages that should be displayed in menus. ```python # Build a menu from live pages that are children of the homepage menu_items = homepage.get_children().live().in_menu() ``` -------------------------------- ### Example HTML structure Source: https://docs.wagtail.org/en/stable/reference/ui/client/classes/controllers_UpgradeController.UpgradeController.html An example of how to use the UpgradeController in HTML. ```html

A new version of Wagtail is available!

``` -------------------------------- ### ImageRenditionField serializer example Source: https://docs.wagtail.org/en/stable/advanced_topics/api/v2/configuration.html Example of using ImageRenditionField to add image renditions to the API. ```python from wagtail.api import APIField from wagtail.images.api.fields import ImageRenditionField class BlogPage(Page): ... api_fields = [ # Adds information about the source image (eg, title) into the API APIField('feed_image'), # Adds a URL to a rendered thumbnail of the image to the API APIField('feed_image_thumbnail', serializer=ImageRenditionField('fill-100x100', source='feed_image')), ... ] ``` -------------------------------- ### GitHub Flavored Markdown Table Example Source: https://docs.wagtail.org/en/stable/contributing/documentation_guidelines.html Example of a simple table using GitHub Flavored Markdown syntax. ```markdown | Browser | Device/OS | | ------------- | --------- | | Stock browser | Android | | IE | Desktop | | Safari | Windows | ``` -------------------------------- ### FormPage model example Source: https://docs.wagtail.org/en/stable/advanced_topics/api/v2/configuration.html Example of exposing form fields to the API for a FormPage model. ```python from wagtail.api import APIField class FormPage(AbstractEmailForm): #... api_fields = [ APIField('form_fields'), ] ``` -------------------------------- ### Project URL Configuration Source: https://docs.wagtail.org/en/stable/advanced_topics/amp.html Example of how to include AMP URLs in your project's main URL configuration. ```python from myapp import amp_urls as wagtail_amp_urls urlpatterns += [ # Change this line to point at your amp_urls instead of Wagtail's urls path('amp/', include(wagtail_amp_urls)), re_path(r'', include(wagtail_urls)), ] ``` -------------------------------- ### Create mysite/templates/includes/header.html Source: https://docs.wagtail.org/en/stable/tutorial/set_up_site_menu.html This template includes logic to display the site menu, linking to the homepage and other live pages marked for inclusion in the menu. ```html+django {% load wagtailcore_tags navigation_tags %}
{% get_site_root as site_root %}
``` -------------------------------- ### Get description example Source: https://docs.wagtail.org/en/stable/extending/custom_tasks.html Example of overriding `get_description` as a class method to provide a human-readable description for the task. ```python @classmethod def get_description(cls): return _("Members of the chosen Wagtail Groups can approve this task") ``` -------------------------------- ### Add blog app to INSTALLED_APPS Source: https://docs.wagtail.org/en/stable/getting_started/tutorial.html Configuration snippet for 'mysite/settings/base.py' showing how to add the new 'blog' app to INSTALLED_APPS. ```python INSTALLED_APPS = [ "blog", # <- Our new blog app. "home", "search", "wagtail.contrib.forms", "wagtail.contrib.redirects", "wagtail.embeds", "wagtail.sites", "wagtail.users", #... other packages ] ``` -------------------------------- ### Using sphobjinv and sphinx.ext.intersphinx to suggest targets Source: https://docs.wagtail.org/en/stable/contributing/documentation_guidelines.html These commands demonstrate how to use `sphobjinv` and Sphinx's built-in `sphinx.ext.intersphinx` extension to explore Sphinx inventories and find link targets. ```sh sphobjinv suggest "https://docs.djangoproject.com/en/stable/_objects/" 'template fragment caching' -su ``` ```python python -m sphinx.ext.intersphinx https://docs.djangoproject.com/en/stable/_objects/ ``` -------------------------------- ### Get actions example Source: https://docs.wagtail.org/en/stable/extending/custom_tasks.html Example of overriding `get_actions` to define available actions for the task based on the user. ```python def get_actions(self, obj, user): if user == self.user: return [ ('approve', "Approve", False), ('reject', "Reject", False), ('cancel', "Cancel", False), ] else: return [] ``` -------------------------------- ### Example: - With initial arguments Source: https://docs.wagtail.org/en/stable/reference/ui/client/classes/controllers_BlockController.BlockController.html Example of using the BlockController with initial arguments. ```html
``` -------------------------------- ### Example: As a button to skip to the top of a section Source: https://docs.wagtail.org/en/stable/reference/ui/client/classes/controllers_FocusController.FocusController.html This example demonstrates using the FocusController as a button to skip to the top of a specific section within the page. ```html

Section title

...lots of content...

``` -------------------------------- ### Image Markdown Example Source: https://docs.wagtail.org/en/stable/contributing/documentation_guidelines.html Example of how to include an image using Markdown syntax. ```markdown ![The TableBlock component in StreamField, with row header, column header, caption fields - and then the editable table](/_static/images/screen40_table_block.png) ``` -------------------------------- ### Get task states user can moderate example Source: https://docs.wagtail.org/en/stable/extending/custom_tasks.html Example of overriding `get_task_states_user_can_moderate` to filter task states based on the user. ```python def get_task_states_user_can_moderate(self, user, **kwargs): if user == self.user: # get all task states linked to the (base class of) current task return TaskState.objects.filter(status=TaskState.STATUS_IN_PROGRESS, task=self.task_ptr) else: return TaskState.objects.none() ``` -------------------------------- ### Example: As an accessible skip link Source: https://docs.wagtail.org/en/stable/reference/ui/client/classes/controllers_FocusController.FocusController.html This example shows how to use the FocusController as an accessible skip link, allowing users to quickly navigate to the main content. ```html Skip to main content ``` -------------------------------- ### Setup Source: https://docs.wagtail.org/en/stable/advanced_topics/images/image_serve_view.html Add an entry for the dynamic image serve view into your URLs configuration. ```python from wagtail.images.views.serve import ServeView urlpatterns = [ ... re_path(r'^images/([^/]*)/(\d*)/([^/]*)/[^/]*$', ServeView.as_view(), name='wagtailimages_serve'), ... # Ensure that the wagtailimages_serve line appears above the default Wagtail page serving route re_path(r'', include(wagtail_urls)), ] ``` -------------------------------- ### Adding all fields Source: https://docs.wagtail.org/en/stable/advanced_topics/api/v2/usage.html Example of adding all available fields to the response. ```http ?fields=* ``` -------------------------------- ### Add the `wagtail start` command Source: https://docs.wagtail.org/en/stable/releases/6.4.html This snippet shows how the `wagtail start` command is documented. ```text wagtail start ``` -------------------------------- ### Markdown Example for Code References Source: https://docs.wagtail.org/en/stable/contributing/documentation_guidelines.html Demonstrates how to use Sphinx reference roles in Markdown for linking to code elements. ```markdown The {class}`~django.db.models.JSONField` class lives in the {mod}`django.db.models.fields.json` module, but it can be imported from the {mod}`models ` module directly. For more info, see {ref}`querying-jsonfield`. ``` -------------------------------- ### python3 not available error Source: https://docs.wagtail.org/en/stable/getting_started/quick_install.html Example of the 'command not found: python3' error. ```sh python3 -m pip install --upgrade pip > command not found: python3 ``` -------------------------------- ### Release metadata directives Source: https://docs.wagtail.org/en/stable/contributing/documentation_guidelines.html Examples of using versionadded and versionchanged directives for release information. ```none .. versionadded:: 2.15 The `WAGTAIL_NEW_SETTING` setting was added. .. versionchanged:: 2.15 The `WAGTAIL_OLD_SETTING` setting was deprecated. ``` -------------------------------- ### Nesting fields Source: https://docs.wagtail.org/en/stable/advanced_topics/api/v2/usage.html Example of nesting 'width' and 'height' of an image field. ```http ?fields=body,feed_image(width,height) ``` -------------------------------- ### min resizing method example Source: https://docs.wagtail.org/en/stable/topics/images.html Example of using the `min` resizing method to cover given dimensions. ```html+django {% image page.photo min-500x200 %} ``` -------------------------------- ### Adding fields Source: https://docs.wagtail.org/en/stable/advanced_topics/api/v2/usage.html Example of adding 'body' and 'feed_image' fields to the response. ```http ?fields=body,feed_image ``` -------------------------------- ### Basic usage Source: https://docs.wagtail.org/en/stable/reference/ui/client/classes/controllers_BulkController.BulkController.html This example demonstrates the basic usage of the BulkController, including how to toggle all checkboxes and individual items. ```html
``` -------------------------------- ### Python not available in path error Source: https://docs.wagtail.org/en/stable/getting_started/quick_install.html Example of the 'command not found: python' error. ```sh python > command not found: python ``` -------------------------------- ### Removing fields Source: https://docs.wagtail.org/en/stable/advanced_topics/api/v2/usage.html Example of removing the 'title' field and adding the 'body' field. ```http ?fields=-title,body ``` -------------------------------- ### Applying Page AMP Template Mixin Source: https://docs.wagtail.org/en/stable/advanced_topics/amp.html Example of applying the PageAMPTemplateMixin to a Wagtail Page model. ```python # /models.py from .amp_utils import PageAMPTemplateMixin class MyPageModel(PageAMPTemplateMixin, Page): ... ``` -------------------------------- ### Filtering by child_of Source: https://docs.wagtail.org/en/stable/advanced_topics/api/v2/usage.html Example of filtering pages by their parent using the `child_of` parameter. ```http GET /api/v2/pages/?child_of=2&show_in_menus=true HTTP 200 OK Content-Type: application/json { "meta": { "total_count": 5 }, "items": [ { "id": 3, "meta": { "type": "blog.BlogIndexPage", "detail_url": "https://api.example.com/api/v2/pages/3/", "html_url": "https://www.example.com/blog/", "slug": "blog", "first_published_at": "2016-09-21T13:54:00Z" }, "title": "About" }, { "id": 10, "meta": { "type": "standard.StandardPage", "detail_url": "https://api.example.com/api/v2/pages/10/", "html_url": "https://www.example.com/about/", "slug": "about", "first_published_at": "2016-08-30T16:52:00Z" }, "title": "About" }, ... ] } ```