0

I have a code line in my views.py:

return render_to_response('errorInsertingData', message='Save isnt complete') 

and the templete errorInsertingData.html code:

<script>
    alert('{{ message }}');
</script>

Why do I get an error:

render_to_string() got an unexpected keyword argument 'message'

my goal is to get the msg 'Save isnt complete' as a popup / msg box.

M.javid
  • 6,387
  • 3
  • 41
  • 56
aayushdagra
  • 89
  • 1
  • 4
  • 14

2 Answers2

1

render_to_response doesn't have a message argument.

What you want is to pass a context dictionary where message is a key.

Which would be:

return render_to_response('errorInsertingData', {"message":"Save isnt complete"}) 
vascop
  • 4,972
  • 4
  • 37
  • 50
1

dont use render_to_response() anymore, it is "deprecated"

use:

return render(request, 'errorInsertingData.html', {'message':'Save isnot complete'}

by doing so, Request Object is automatically in the context available

or if you just want to return a string, then use:

return HttpResponse('Save isnot complete')
doniyor
  • 36,596
  • 57
  • 175
  • 260
  • the render almost works. it gives a popup but there is no msg there. its blank. – aayushdagra Sep 13 '15 at 09:10
  • @aayushdagra it must be some js typo, – doniyor Sep 13 '15 at 09:13
  • there is no js. jse the templete i gave.... took the idea from here: http://stackoverflow.com/questions/28240746/django-how-to-implement-alertpopup-message-after-complete-method-in-view – aayushdagra Sep 13 '15 at 09:18
  • @aayushdagra `alert()` IS a js. ;) if you render to correct template and invoke the alert in correct place, then it should work – doniyor Sep 13 '15 at 09:20