prymitive / bootstrap-breadcrumbs

Django template tags for easy breadcrumbs using twitter bootstrap css classes or custom template
django-bootstrap-breadcrumbs.readthedocs.org
MIT License
92 stars 47 forks source link

Templatetag is causing 'RemovedInDjango110Warning: render() must be called with a dict, not a RequestContext.' #28

Closed seddonym closed 8 years ago

seddonym commented 8 years ago

When I run django-bootstrap-breadcrumbs in Django 1.9.10, I get the following deprecation warning:

RemovedInDjango110Warning: render() must be called with a dict, not a RequestContext.

This is because the render_breadcrumbs receives a RequestContext object and then subsequently passes it to render_to_string.

I suggest something along the lines of this, where we check the Django version and if it's 1.9 or later than we go through the RequestContext object and puts it into a dict, before passing it.

from distutils.version import StrictVersion
import django

def render_breadcrumbs(context, *args):
...
    if StrictVersion(django.get_version()) >= StrictVersion('1.9'):
        # Passing a RequestContext to render_to_string is deprecated or not allowed; convert the context to a dict
        context_dict = {}
        for d in context.dicts:
            context_dict.update(d)
        return mark_safe(template.loader.render_to_string(
            template_path, context_dict, request=context['request']))
prymitive commented 8 years ago

Well, there is #27, I'll try to commit a fix and tag a release when I have a chance

seddonym commented 8 years ago

Ah I hadn't seen that. I think this approach would be better backward compatible, as people may use other context variables in their overridden versions of the templates.

seddonym commented 8 years ago

Oh I see I'm just repeating what you said. https://github.com/prymitive/bootstrap-breadcrumbs/commit/f2e6b17afa41cf7c7498baa67c09dd85191894bb is much nicer. I'll close this issue, thanks.