title: Error Converting HTML to PDF in Django
body: <p>Django is throwing "'NoneType' object has no attribute 'encode'" error. I'm attempting to use django-easy-pdf's PDFTemplateView in order to generate a pdf report form. Only problem is, the debugger isn't giving me a whole lot of direction. I'm hoping a second pair of eyes can potentially help.</p>
  
  <p>Any and all help is appreciated!</p>
  
  <h1>Views.py</h1>
  
  <pre><code>class ToolReport(PDFTemplateView):
  model = ToolCalibration
  template_name = "report.html"
  inlines = [SerialFormSet, PartFormSet]
  
  def get_context_data(self, **kwargs):
      context = super(ToolReport, self).get_context_data(**kwargs)
      if 'pk' in self.kwargs:
          context['tool'] = ToolCalibration.objects.get(id=self.kwargs['pk'])
  
      return context
  </code></pre>
  
  <h1>Models.py</h1>
  
  <pre><code>from django.db import models
  from django.core.urlresolvers import reverse
  from selectables.models import EnterpriseSchema, State, Country
  
  class ToolStatus(models.Model):
      status = models.CharField(max_length=40)
  
      def __unicode__(self):
          return (self.status)
  
  class CalibrationInterval(models.Model):
      interval = models.CharField(max_length=25)
  
      def __unicode__(self):
          return (self.interval)
  
  class CalibrationMethod(models.Model):
      method = models.CharField(max_length=25)
  
      def __unicode__(self):
          return (self.method)
  
  class Manufacturer(models.Model):
      name = models.CharField(max_length=35)
  
      def __unicode__(self):
          return (self.name)
  
  class UsageLocation(models.Model):
      location = models.CharField(max_length=75)
      owner = models.CharField(max_length=25, default="AVMATS")
  
      def __unicode__(self):
          return (self.location)
  
  
  class Vendor(models.Model):
      name = models.CharField(max_length=255)
      street_address = models.CharField(max_length=255)
      city = models.CharField(max_length=35)
      state = models.ForeignKey(State, null=True)
      country = models.ForeignKey(Country, default=lambda:
      Country.objects.get(name__exact="United States"))
      zipcode = models.IntegerField()
      contact_title = models.CharField(max_length=50)
      free_phone = models.CharField("Toll free phone number", max_length=30, blank=True)
      phone_number = models.CharField(max_length=30, blank=True)
      extension = models.CharField("Phone extension", max_length=30, blank=True)
      email_address = models.CharField(max_length=75, blank=True)
      website = models.CharField(max_length=75, blank=True)
      free_fax = models.CharField("Toll free fax", max_length=30, blank=True)
      fax_number = models.CharField(max_length=50, blank=True)
      notes =  models.TextField(blank=True)
  
  
      def __unicode__(self):
          return (self.name)
  
  class ToolCalibration(models.Model):
      schema = models.ForeignKey(EnterpriseSchema, verbose_name="Location")
      old_control_number = models.CharField(max_length=25, blank=True)
      due_date = models.DateField()
      last_certified = models.DateField()
      tool_status = models.ForeignKey(ToolStatus)
      calibration_interval = models.ForeignKey(CalibrationInterval)
      calibration_method = models.ForeignKey(CalibrationMethod)
      usage_location = models.ForeignKey(UsageLocation)
      description = models.CharField(max_length=75)
      manufacturer = models.ForeignKey(Manufacturer)
      usage_range = models.CharField(max_length=35)
      notes = models.TextField(blank=True)
      po_required = models.BooleanField("Purchase order required")
      po_number = models.CharField("Purchase order number", max_length=35, blank=True, null=True)
      ra_number = models.CharField("Return authorization number", max_length=35, blank=True)
      calibration_cost = models.CharField(max_length=30, blank=True)
      vendor = models.ForeignKey(Vendor)
      date_sent = models.DateField(blank=True)
      date_returned = models.DateField(blank=True)
      man_hours = models.CharField("In-house man hours", max_length=25, blank=True)
      technician = models.CharField(max_length=45)
      facility = models.CharField(max_length=45)
      out_of_tolerance = models.BooleanField()
      tolerance_notes = models.TextField(blank=True)
      success_url = "/toolcal/success"
  
      def __unicode__(self):
          return (u"%s: " %self.id) + (u"%s" %self.description) 
  
  class SerialNumber(models.Model):
      tool = models.ForeignKey(ToolCalibration)
      serial = models.CharField(max_length=35)
  
      def __unicode__(self):
          return (self.serial)
  
  class PartNumber(models.Model):
      tool = models.ForeignKey(ToolCalibration)
      number = models.CharField(max_length=35)
  
      def __unicode__(self):
          return (self.number)
  
  class Note(models.Model):
      tool = models.ForeignKey(ToolCalibration)
      description = models.CharField(max_length=50)
      pub_date = models.DateTimeField()
  
      def __unicode__(self):
          return self.description
  </code></pre>
  
  <h1>HTML:</h1>
  
  <pre><code>&lt;html&gt;
  
  &lt;head&gt;
      &lt;link rel="stylesheet" href="/media/themes/txt/css/report.css" /&gt;
  &lt;/head&gt;
  
  &lt;body&gt;  
      &lt;div class="content"&gt;
          &lt;div class="row"&gt;
              &lt;div class="12u"&gt;
                  &lt;h1&gt;Aviation Turbines International&lt;/h1&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="row"&gt;
              &lt;div class="7u"&gt;
                  &lt;h2&gt;In-House Calibration Report For: &lt;/h2&gt;
              &lt;/div&gt;
              &lt;div class="5u"&gt;
                  &lt;h2&gt;ID Number { tool.id }}&lt;/h2&gt; 
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="row"&gt;
              &lt;div class="6u"&gt;
                  &lt;h2&gt;Calibration Due Date: {{ tool.due_date }} &lt;/h2&gt;
              &lt;/div&gt;
              &lt;div class="6u"&gt;
                  &lt;h2&gt;Date Last Calibrated: {{ tool.last_certified }} &lt;/h2&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="row"&gt;
              &lt;div class="12u"&gt;
                  &lt;h1&gt;Tool (Equipment) Identification&lt;/h1&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="row"&gt;
              &lt;div class="12u"&gt;
                  &lt;h2&gt;Description: {{ tool.description }}&lt;/h2&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="row"&gt;
              &lt;div class="12u"&gt;
                  &lt;h2&gt;Manufacturer: {{ tool.manufacturer }}&lt;/h2&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          {% if tool.partnumber %}
              &lt;div class="row"&gt;
                  &lt;div class="12u"&gt;
                      &lt;h2&gt;Model/Part Number(s): {% for part_number in tool.partnumber_set.all %}[{{ part_number }}] {% endfor %}&lt;/h2&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          {% endif %}
          {% if tool.serialnumber %}
              &lt;div class="row"&gt;
                  &lt;div class="12u"&gt;
                      &lt;h2&gt;Serial Number(s): {% for serial_number in tool.serialnumber_set.all %}[{{ serial_number }}] {% endfor %}&lt;/h2&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          {% endif %}
          {% if tool.usage_range %}
              &lt;div class="row"&gt;
                  &lt;div class="6u"&gt;
                      &lt;h2&gt;Full Range: {{ tool.usage_range }}&lt;/h2&gt;
                  &lt;/div&gt;
                  &lt;div class="6u"&gt;
                      &lt;h2&gt;Limited Range: &lt;/h2&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          {% endif %}
          &lt;div class="row"&gt;
              &lt;div class="12u"&gt;
                  &lt;h1&gt;Item Condition/Special Requirements-Calibration Test Results&lt;/h1&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="row"&gt;
              &lt;div class="12u"&gt;
                  &lt;h2&gt;Accomplished in Accordance with Manufacturer's Specifications and/or Standard Practices&lt;/h2&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="box"
              &lt;div class="row"&gt;
                  &lt;div class="box"
                      &lt;div class="6u"&gt;
                          &lt;h2&gt;As Received&lt;/h2&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="box"
                      &lt;div class="6u"&gt;
                          &lt;h2&gt;As Returned&lt;/h2&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="box"
              &lt;div class="row"&gt;
                  &lt;div class="box"
                      &lt;div class="6u"&gt;
                          &lt;h2&gt;[] In Tolerance &lt;/h2&gt;
                          &lt;h2&gt;[] Out of Tolerance &lt;/h2&gt;
                          &lt;h2&gt;[] Limited Calibration &lt;/h2&gt;
                          &lt;h2&gt;[] Inoperative &lt;/h2&gt;
                          &lt;h2&gt;[] Note:  &lt;/h2&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="box"
                      &lt;div class="6u"&gt;
                          &lt;h2&gt;[] In Tolerance &lt;/h2&gt;
                          &lt;h2&gt;[] Out of Tolerance &lt;/h2&gt;
                          &lt;h2&gt;[] Limited Calibration &lt;/h2&gt;
                          &lt;h2&gt;[] Inoperative &lt;/h2&gt;
                          &lt;h2&gt;[] Adjusted  &lt;/h2&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="row"&gt;
              &lt;div class="12u"&gt;
                  &lt;h2&gt;This equipment was checked/calibrated through [] full or [] limited range, and kept within _____ accuracy&lt;/h2&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="row"&gt;
              &lt;div class = "box"&gt;
                  &lt;div class="2u"&gt;                    
                      &lt;h2&gt;Standard&lt;/h2&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class = "box"&gt;
                  &lt;div class="2u"&gt;                    
                      &lt;h2&gt;Actual Reading&lt;/h2&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class = "box"&gt;
                  &lt;div class="3u"&gt;                    
                      &lt;h2&gt;Deviation&lt;/h2&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class = "box"&gt;
                  &lt;div class="3u"&gt;                    
                      &lt;h2&gt;In/Out of Cal&lt;/h2&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class = "box"&gt;
                  &lt;div class="3u"&gt;                    
                      &lt;h2&gt;Final Reading&lt;/h2&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          {% for i in "xxxxxxxxxxxxx" %}
              &lt;div class="row"&gt;
                  &lt;div class = "box"&gt;
                      &lt;div class="2u"&gt;
                          &lt;h2&gt;Standard&lt;/h2&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class = "box"&gt;
                      &lt;div class="2u"&gt;
                          &lt;h2&gt;Actual Reading&lt;/h2&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class = "box"&gt;
                      &lt;div class="3u"&gt;
                          &lt;h2&gt;Deviation&lt;/h2&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class = "box"&gt;
                      &lt;div class="3u"&gt;
                          &lt;h2&gt;In/Out of Cal&lt;/h2&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class = "box"&gt;
                      &lt;div class="3u"&gt;
                          &lt;h2&gt;Final Reading&lt;/h2&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          {% endfor %}
      &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>