question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deprecation warnings when used with Django 1.9

See original GitHub issue

When used in a Django 1.9 project crispy-forms code produces some deprecation warnings:

python2.7/site-packages/crispy_forms/utils.py:157: RemovedInDjango110Warning: render() must be called with a dict, not a RequestContext.
  html = template.render(context)

python2.7/site-packages/crispy_forms/layout.py:199: RemovedInDjango110Warning: The  context_instance argument of render_to_string is deprecated.
  return render_to_string(template, {'input': self}, context)

python2.7/site-packages/django/template/loader.py:97: RemovedInDjango110Warning: render() must be called with a dict, not a RequestContext.
  return template.render(context, request)

I’m not sure whether this list is complete, but this is all I get in the test suite of one of my projects. I have not observed any wrong behavior in my application yet.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kavdevcommented, Dec 22, 2015

Two more instances for you:

python3.4/site-packages/crispy_forms/bootstrap.py:90: RemovedInDjango110Warning: The context_instance argument of render_to_string is deprecated.
  return render_to_string(template, extra_context, context)

python3.4/site-packages/crispy_forms/templatetags/crispy_forms_tags.py:222: RemovedInDjango110Warning: render() must be called with a dict, not a Context.
  return template.render(c)

Related information (new in Django 1.8):

Template objects must provide a render() method whose signature differs slightly from the Django template language’s render().

Instead of:

from django.template import Context
from django.template.loader import get_template

template = get_template('hello.html')
html = template.render(Context({'name': 'world'}))

You should write:

from django.template.loader import get_template

template = get_template('hello.html')
html = template.render({'name': 'world'})

And instead of:

from django.template import RequestContext
from django.template.loader import get_template

template = get_template('hello.html')
html = template.render(RequestContext(request, {'name': 'world'}))

You should write:

from django.template.loader import get_template

template = get_template('hello.html')
html = template.render({'name': 'world'}, request)

Passing a Context or a RequestContext is still possible when the template is loaded by a DjangoTemplates backend but it’s deprecated and won’t be supported in Django 1.10.

If you’re loading a template while you’re rendering another template with the Django template language and you have access to the current context, for instance in the render() method of a template tag, you can use the current Engine directly. Instead of:

from django.template.loader import get_template
template = get_template('included.html')

You can write:

template = context.template.engine.get_template('included.html')

This will load the template with the current engine without triggering the multiple template engines machinery, which is usually the desired behavior. Unlike previous solutions, this returns a django.template.Template, like get_template() used to in Django 1.7 and earlier, avoiding all backwards-compatibility problems.

0reactions
janddcommented, Dec 23, 2015

@kavdev thanks a lot

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix a Deprecation Warning in Django 1.9 - Stack Overflow
It can be easily fixed by removing the use of RequestContext or Context from render() and simply passing a dictionary. Leaving it as...
Read more >
Django Deprecation Timeline
This document outlines when various pieces of Django will be removed or altered in a backward incompatible way, following their deprecation, as per...
Read more >
Django 1.9 deprecation warnings app_label - YouTube
Django : Django 1.9 deprecation warnings app_label [ Beautify Your Computer : https://www.hows.tech/p/recommended.html ] Django : Django 1.9 ...
Read more >
Django 1.9 Deprecation Warnings Applabel - ADocLib
Using 'PYENV' to manage different python versions and running this in a virtual environment.System check framework | Django documentation Django disable one.
Read more >
Fix deprecation warnings shown whilst running Django 1.8
7/site-packages/rest_framework/ > serializers.py:155: RemovedInDjango19Warning: SortedDict is deprecated and > will be removed in Django 1.9. > return ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found