Skip to content

Fixing invalid HTML Wagtail pages that error

Pat Phongsvirajati edited this page Oct 19, 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/

# Target the space

cf target -s [environment]


# Shell into the app

cf ssh [app]


# 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

# Go to the app directory

cd app

# 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()