render_to_string() complains of a NoneType error
Question: So I'm testing my code in `python manage.py shell`, however I'm getting the
following error: `AttributeError: 'NoneType' object has no attribute 'find'`.

Here's what I've done in the app's `models.py`:

    
    
    from djmoney.models.fields import MoneyField
    from django.template.loader import render_to_string
    from django.db import models
    from datetime import date
    import mandrill
    

<...>

    
    
    def email_invoice(self):
        dated, amount, subtenant = self.dated, self.amount, self.subtenant.name
        net_amount = self.amount / 1.13
        hst = amount - net_amount
        context = {
                    'date': dated,
                    'amount': amount,
                    'net_amount': net_amount,
                    'hst': hst,
                    'subtenant': subtenant
        }
        msg_html = render_to_string('email/invoice.html', context)
        message = {
                    'to': [{'email': '<left out>',
                            'name': '<left out>',
                            'type': 'to'}],
                    'subject': 'Testing',
                    'html': msg_html,
                    'from_email': '<left out>',
                    'from_name': '<left out>'
        }
        try:
            mandrill_client = mandrill.Mandrill('<left out>')
            result = mandrill_client.messages.send(message=message)
        except mandrill.Error as e:
            print('A mandrill error occurred: %s - %s' % (e.__class__, e))
            raise
    

The traceback seems to suggest that the issue is with `render_to_string()`,
but I don't see what I've done wrong with its implementation: I tested that
the template exists (it's an email template) in the shell. In fact,
`render_to_string('email/invoice.html')` without a context works fine. The
issue is with the context.

I tried playing around with a simple dict in the shell, like `context =
{'hst': 123}` and that works too. For some reason it doesn't like my dict
above, and complains of a NoneType. I individually checked each object field
to make sure it exists and that it returns a value in the shell.

Any idea where this NoneType is coming from?

EDIT: Here is the full traceback

    
    
    Traceback (most recent call last):
      File "<console>", line 1, in <module>
      File "/Users/cyehia/Documents/Apps/gcap/rental/models.py", line 41, in email_invoice
        msg_html = render_to_string('email/invoice.html', context)
      File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/django/template/loader.py", line 99, in render_to_string
        return template.render(context, request)
      File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/django/template/backends/django.py", line 74, in render
        return self.template.render(context)
      File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/django/template/base.py", line 209, in render
        return self._render(context)
      File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/django/template/base.py", line 201, in _render
        return self.nodelist.render(context)
      File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/django/template/base.py", line 903, in render
        bit = self.render_node(node, context)
      File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/django/template/debug.py", line 79, in render_node
        return node.render(context)
      File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/django/template/debug.py", line 92, in render
        output = force_text(output)
      File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/django/utils/encoding.py", line 90, in force_text
        s = six.text_type(s)
      File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/djmoney/models/fields.py", line 133, in __str__
        locale = self.__get_current_locale()
      File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/djmoney/models/fields.py", line 103, in __get_current_locale
        locale = translation.to_locale(translation.get_language())
      File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 185, in to_locale
        return _trans.to_locale(language)
      File "/Users/cyehia/Documents/Apps/venv/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 75, in to_locale
        p = language.find('-')
    AttributeError: 'NoneType' object has no attribute 'find'
    


Answer: The issue seems to be with an [incompatibly between Django 1.8 and django-
money](http://github.com/django-money/django-money/issues/118). I'd try
manually activating a language with:

    
    
    from django.utils.translation import activate 
    
    def email_invoice(self):
        <....>
        activate('en')
        msg_html = render_to_string('email/invoice.html', context)
    

