title: Django Wagtail 'expected string or bytes-like object' error
body: <p>I've been having some trouble figuring out what exactly is causing this error in my code. My main pages render but when I try to open a child page I get the expected string error. Any help debugging this greatly appreciated.</p>
  
  <p>Traceback Below: </p>
  
  <pre><code>    Internal Server Error: /resonate/page-2/
  Traceback (most recent call last):
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
      response = get_response(request)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/core/handlers/base.py", line 156, in _get_response
      response = self.process_exception_by_middleware(e, request)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/core/handlers/base.py", line 154, in _get_response
      response = response.render()
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/response.py", line 106, in render
      self.content = self.rendered_content
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/response.py", line 83, in rendered_content
      content = template.render(context, self._request)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/backends/django.py", line 61, in render
      return self.template.render(context)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py", line 171, in render
      return self._render(context)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py", line 163, in _render
      return self.nodelist.render(context)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py", line 937, in render
      bit = node.render_annotated(context)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
      return self.render(context)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/loader_tags.py", line 150, in render
      return compiled_parent._render(context)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py", line 163, in _render
      return self.nodelist.render(context)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py", line 937, in render
      bit = node.render_annotated(context)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
      return self.render(context)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/loader_tags.py", line 62, in render
      result = block.nodelist.render(context)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py", line 937, in render
      bit = node.render_annotated(context)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
      return self.render(context)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/loader_tags.py", line 62, in render
      result = block.nodelist.render(context)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py", line 937, in render
      bit = node.render_annotated(context)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py", line 904, in render_annotated
      return self.render(context)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py", line 987, in render
      output = self.filter_expression.resolve(context)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py", line 698, in resolve
      new_obj = func(obj, *arg_vals)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/wagtail/core/templatetags/wagtailcore_tags.py", line 75, in richtext
      html = expand_db_html(value)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/wagtail/core/rich_text/__init__.py", line 30, in expand_db_html
      return FRONTEND_REWRITER(html)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/wagtail/core/rich_text/rewriters.py", line 81, in __call__
      html = rewrite(html)
    File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/wagtail/core/rich_text/rewriters.py", line 71, in __call__
      return FIND_A_TAG.sub(self.replace_tag, html)
  TypeError: expected string or bytes-like object
      Django Version: 2.1.1
      Python Version: 3.6.6
      Installed Applications:
      ['accounts',
       'home',
       'search',
       'design_system',
       'wagtail.contrib.settings',
       'wagtail.contrib.forms',
       'wagtail.contrib.redirects',
       'wagtail.contrib.routable_page',
       'wagtail.contrib.modeladmin',
       'wagtailmenus',
       'wagtail.embeds',
       'wagtail.sites',
       'wagtail.users',
       'wagtail.snippets',
       'wagtail.documents',
       'wagtail.images',
       'wagtail.search',
       'dashboard',
       'wagtail.admin',
       'wagtail.core',
       'modelcluster',
       'taggit',
       'condensedinlinepanel',
       'django.contrib.admin',
       'django.contrib.auth',
       'django.contrib.contenttypes',
       'django.contrib.sessions',
       'django.contrib.messages',
       'django.contrib.staticfiles']
      Installed Middleware:
      ['django.middleware.security.SecurityMiddleware',
       'django.contrib.sessions.middleware.SessionMiddleware',
       'django.middleware.common.CommonMiddleware',
       'django.middleware.csrf.CsrfViewMiddleware',
       'django.contrib.auth.middleware.AuthenticationMiddleware',
       'django.contrib.messages.middleware.MessageMiddleware',
       'django.middleware.clickjacking.XFrameOptionsMiddleware',
       'wagtail.core.middleware.SiteMiddleware',
       'wagtail.contrib.redirects.middleware.RedirectMiddleware']
  
  
      Template error:
      In template /Users/saeahmad/Desktop/code/auxe/AUXE_Design_System/auxe_cms/design_system/templates/design_system/base.html, error at line 0
         expected string or bytes-like object
         1 : {% load static wagtailcore_tags wagtailimages_tags menu_tags %}
         2 : &lt;!DOCTYPE html&gt;
         3 : &lt;html lang="en"&gt;
         4 : 
         5 : &lt;head&gt;
         6 :     &lt;meta charset="utf-8"&gt;
         7 :     &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;
         8 :     &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
         9 : 
         10 :     &lt;title&gt;{% block title %}{{ main_page.title }}{% if main_page.description %} | {{ main_page.description }}{% endif %}{% endblock title %}&lt;/title&gt;
  
  
      Traceback:
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
        34.             response = get_response(request)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
        156.                 response = self.process_exception_by_middleware(e, request)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
        154.                 response = response.render()
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/response.py" in render
        106.             self.content = self.rendered_content
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/response.py" in rendered_content
        83.         content = template.render(context, self._request)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/backends/django.py" in render
        61.             return self.template.render(context)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py" in render
        171.                     return self._render(context)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py" in _render
        163.         return self.nodelist.render(context)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py" in render
        937.                 bit = node.render_annotated(context)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py" in render_annotated
        904.             return self.render(context)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/loader_tags.py" in render
        150.             return compiled_parent._render(context)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py" in _render
        163.         return self.nodelist.render(context)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py" in render
        937.                 bit = node.render_annotated(context)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py" in render_annotated
        904.             return self.render(context)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/loader_tags.py" in render
        62.                 result = block.nodelist.render(context)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py" in render
        937.                 bit = node.render_annotated(context)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py" in render_annotated
        904.             return self.render(context)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/loader_tags.py" in render
        62.                 result = block.nodelist.render(context)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py" in render
        937.                 bit = node.render_annotated(context)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py" in render_annotated
        904.             return self.render(context)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py" in render
        987.             output = self.filter_expression.resolve(context)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/django/template/base.py" in resolve
        698.                 new_obj = func(obj, *arg_vals)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/wagtail/core/templatetags/wagtailcore_tags.py" in richtext
        75.         html = expand_db_html(value)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/wagtail/core/rich_text/__init__.py" in expand_db_html
        30.     return FRONTEND_REWRITER(html)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/wagtail/core/rich_text/rewriters.py" in __call__
        81.             html = rewrite(html)
  
      File "/Users/saeahmad/.pyenv/versions/auxe_cms/lib/python3.6/site-packages/wagtail/core/rich_text/rewriters.py" in __call__
        71.         return FIND_A_TAG.sub(self.replace_tag, html)
  
      Exception Type: TypeError at /resonate/page-2/
      Exception Value: expected string or bytes-like object
  </code></pre>
  
  <p>I've also looked through my base.html file and can't seem to find any errors there so I assume it may be with within my models for the contentpage?</p>
  
  <pre><code>class ContentPage(Page):
      body = StreamField([
          ('heading', blocks.CharBlock(classname="full title")),
          ('paragraph', blocks.RichTextBlock()),
          ('rich_text', blocks.RichTextBlock(icon='doc-full', label='Rich Text')),
          ('two_columns', TwoColumnBlock()),
          ('image', ImageChooserBlock(icon="image")),
          ('embedded_video', EmbedBlock(icon="media")),
          ('html', blocks.RawHTMLBlock(icon='site', label='HTML')),
  
      ],null=True,blank=True)
  
      content_panels = Page.content_panels + [
          StreamFieldPanel('body'),
      ]
  
      @property
      def main_page(self):
          return self.get_parent().specific
  
      def get_context(self, request, *args, **kwargs):
          context = super(ContentPage, self).get_context(request, *args, **kwargs)
          context['main_page'] = self.main_page
          context['content'] = self
          return context
  </code></pre>