New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecation warnings when used with Django 1.9 #553

Closed
jandd opened this Issue Dec 19, 2015 · 10 comments

Comments

Projects
None yet
3 participants
@jandd
Contributor

jandd commented Dec 19, 2015

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.

@jandd jandd changed the title from Deprecation warning when used with Django 1.9 to Deprecation warnings when used with Django 1.9 Dec 19, 2015

@kavdev

This comment has been minimized.

Show comment
Hide comment
@kavdev

kavdev Dec 22, 2015

Contributor

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.

Contributor

kavdev commented 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.

@kavdev

This comment has been minimized.

Show comment
Hide comment
@kavdev

kavdev Dec 22, 2015

Contributor

I'm going to put in a pull request in a bit, but fair warning: keeping < 1.8 compatibility will result in some ugly code. (It actually isn't too bad)

Contributor

kavdev commented Dec 22, 2015

I'm going to put in a pull request in a bit, but fair warning: keeping < 1.8 compatibility will result in some ugly code. (It actually isn't too bad)

@carltongibson

This comment has been minimized.

Show comment
Hide comment
@carltongibson

carltongibson Dec 23, 2015

Collaborator

If anyone wants a Christmas project, I'd be happy to take a PR on these issues! 😃

Collaborator

carltongibson commented Dec 23, 2015

If anyone wants a Christmas project, I'd be happy to take a PR on these issues! 😃

@kavdev

This comment has been minimized.

Show comment
Hide comment
@kavdev
Contributor

kavdev commented Dec 23, 2015

@carltongibson

This comment has been minimized.

Show comment
Hide comment
@carltongibson

carltongibson Dec 23, 2015

Collaborator

Already merged, but there are other warnings right?

Collaborator

carltongibson commented Dec 23, 2015

Already merged, but there are other warnings right?

@kavdev

This comment has been minimized.

Show comment
Hide comment
@kavdev

kavdev Dec 23, 2015

Contributor

Nope, got all of them. They are all part of the same deprecation. I take that back. Let me look into his second reported warning.

Contributor

kavdev commented Dec 23, 2015

Nope, got all of them. They are all part of the same deprecation. I take that back. Let me look into his second reported warning.

@carltongibson

This comment has been minimized.

Show comment
Hide comment
@carltongibson

carltongibson Dec 23, 2015

Collaborator

@kavdev OK. thanks for the input!

FYI I'm looking for a release the w/b 4th Jan

Collaborator

carltongibson commented Dec 23, 2015

@kavdev OK. thanks for the input!

FYI I'm looking for a release the w/b 4th Jan

@kavdev

This comment has been minimized.

Show comment
Hide comment
@kavdev

kavdev Dec 23, 2015

Contributor

@carltongibson: Sounds good. #555

Contributor

kavdev commented Dec 23, 2015

@carltongibson: Sounds good. #555

@carltongibson

This comment has been minimized.

Show comment
Hide comment
@carltongibson

carltongibson Dec 23, 2015

Collaborator

Good work @kavdev. Thanks.

Collaborator

carltongibson commented Dec 23, 2015

Good work @kavdev. Thanks.

@jandd

This comment has been minimized.

Show comment
Hide comment
@jandd

jandd Dec 23, 2015

Contributor

@kavdev thanks a lot

Contributor

jandd commented Dec 23, 2015

@kavdev thanks a lot

amigo00678 added a commit to amigo00678/django that referenced this issue May 1, 2017

Update context.py
A simple fix for an issue mentioned here:
https://code.djangoproject.com/ticket/27722
translate/pootle#5442
django-crispy-forms/django-crispy-forms#553
Can reproduce this for python 3.5 and django 1.11. Using django-bootstrap-breadcrumbs.
http://django-bootstrap-breadcrumbs.readthedocs.io/en/latest/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment