Skip to content

Fixing invalid HTML Wagtail pages that error

Pat Phongsvirajati edited this page Sep 14, 2018 · 14 revisions

After upgrading from Wagtail 1.x to 2.x, we started to have issues with the new RTE editor, Draftail, in which it will not understand HTML that is invalid. Therefore, there are times where it is necessary to shell into a particular page in order to fix those errors so that the page may be restored for editing in Wagtail again. Always perform these commands within dev first and once successful, do the same thing to prod.

Separate documentation about how to shell into a cloud.gov app can be found here: https://cloud.gov/docs/apps/using-ssh/

# Shell into the cms app

cf ssh cms


# Configure ssh session environment to run python

export DEPS_DIR=/home/vcap/deps
for f in /home/vcap/profile.d/*.sh; do source "$f"; done


# Use Django python API to access models

./manage.py shell


# From the custom home models and import the model you would like to edit. Look at models here https://github.com/fecgov/fec-cms/blob/develop/fec/home/models.py

from home.models import [ModelClassName]


# Get the page object by ID

page = ReportingExamplePage.objects.get(id=[ID#])


# Access the page's stream_data field

page.body.stream_data


# Replace the stream_data field with corrected HTML

page.body.stream_data = [{'type': 'paragraph', 'value': ''}]


# Save the page

page.save()