Why do I get this error "context must be a dict rather than Context." ?

7,951 views
Skip to first unread message

Pubudu Goonetilleke

unread,
Apr 29, 2017, 5:44:57 PM4/29/17
to Django users

My code : I am following tutorial on Django site and this is where I got stuck

"current_datetime"
I am not sure why I get the Type Error at line 20. Its same as tutorial. 


When I run the server, I get the following error : 

TypeError at /time/

context must be a dict rather than Context.
Request Method:GET
Request URL:http://127.0.0.1:8000/time/
Django Version:1.11
Exception Type:TypeError
Exception Value:
context must be a dict rather than Context.
Exception Location:D:\Users\Pubudu\AppData\Local\Programs\Python\Python36\lib\site-packages\django\template\context.py in make_context, line 287
Python Executable:D:\Users\Pubudu\AppData\Local\Programs\Python\Python36\python.exe
Python Version:3.6.1
Python Path:
['C:\\Users\\Pubudu\\workspace\\hello',
 'D:\\Users\\Pubudu\\AppData\\Local\\Programs\\Python\\Python36\\python36.zip',
 'D:\\Users\\Pubudu\\AppData\\Local\\Programs\\Python\\Python36\\DLLs',
 'D:\\Users\\Pubudu\\AppData\\Local\\Programs\\Python\\Python36\\lib',
 'D:\\Users\\Pubudu\\AppData\\Local\\Programs\\Python\\Python36',
 'D:\\Users\\Pubudu\\AppData\\Local\\Programs\\Python\\Python36\\lib\\site-packages']
Server time:Sat, 29 Apr 2017 21:35:31 +0000

Traceback Switch to copy-and-paste view

  • D:\Users\Pubudu\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\handlers\exception.py in inner
    1.             response = get_response(request)
      ...
  • D:\Users\Pubudu\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\handlers\base.py in _get_response
    1.                 response = self.process_exception_by_middleware(e, request)
      ...
  • D:\Users\Pubudu\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\handlers\base.py in _get_response
    1.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)


Tim Graham

unread,
Apr 29, 2017, 6:45:32 PM4/29/17
to Django users
It looks like the tutorial you're following hasn't been updated for Django 1.11.

Line 20 should pass a dict rather than Context:

t.render({'current_date': now})

It's related to this change in Django 1.11: https://docs.djangoproject.com/en/dev/releases/1.11/#django-template-backends-django-template-render-prohibits-non-dict-context

Pubudu Goonetilleke

unread,
Apr 30, 2017, 10:24:48 AM4/30/17
to Django users
Thank you very much.

pallavi pund

unread,
Nov 20, 2017, 7:38:26 AM11/20/17
to Django users
This helped me too . thank you

Amitesh Sahay

unread,
Nov 20, 2017, 9:51:27 AM11/20/17
to Django users, pallavi pund
As far as I know, context is always built through key, value pair. But check for it before coming to any conclusion

Hello,

Regards,
Amitesh Sahay

primary :: 91-907 529 6235



    1.                 response = self.process_exception_by_ middleware(e, request)
      ...
  • D:\Users\Pubudu\AppData\Local\ Programs\Python\Python36\lib\ site-packages\django\core\ handlers\base.py in _get_ response
    1.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)


    --
    You received this message because you are subscribed to the Google Groups "Django users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
    To post to this group, send email to django...@googlegroups.com.
    Visit this group at https://groups.google.com/group/django-users.
    To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/07154b8b-6812-4491-96de-02f89606976c%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    Reply all
    Reply to author
    Forward
    0 new messages