1

I am running a django application and getting the following error:

TypeError at /login

render_to_string() got an unexpected keyword argument 'status'

Request Method:     GET

Request URL:    http://10.107.44.122:8002/login?next=/

Django Version:     1.7.1

Exception Type:     TypeError

Exception Value: render_to_string() got an unexpected keyword argument 'status'

Exception Location:     /usr/local/lib/python2.7/dist-packages/django/shortcuts.py in render_to_response, line 23

Python Executable:  /usr/bin/python

Python Version:     2.7.6

The only place I could think of where the error might be coming from is :

render_to_response('login.html', context, status=status, context_instance=RequestContext(request))

status is supposed to be expected keyword for render_to_response, then why this error?

Wtower
  • 17,145
  • 11
  • 98
  • 72
Sumit
  • 55
  • 1
  • 4

2 Answers2

5

You could use the render shortcut instead of render_to_response. The render method does take a status argument in all versions of Django. It's a nicer method to use anyway, because you don't need to supply a RequestContext.

from django.shortcuts import render

def my_view(request):
    context ={'foo': 'bar'}
    status = 200
    return render(request, 'login.html', context, status=status)
Alasdair
  • 278,338
  • 51
  • 534
  • 489
3

The status argument is accepted in Django 1.8, not in 1.7. Compare the documentation for the render_to_response methods in 1.8 and 1.7.

solarissmoke
  • 27,879
  • 12
  • 62
  • 68