Django 1.11 TypeError context must be a dict rather than Context

后端 未结 3 1334
没有蜡笔的小新
没有蜡笔的小新 2020-12-01 15:33

Just received the Sentry error TypeError context must be a dict rather than Context. on one of my forms. I know it has something to do with Django 1.11, but I

3条回答
  •  无人及你
    2020-12-01 15:58

    Migrated from Django 1.8 to Django 1.11.6

    Wherever i had a RequestContext class, there is a method flatten() wich return the result as a dict.

    So if the class is RequestContext....

    return t.render(context)
    

    becomes

    return t.render(context.flatten())
    

    And in a case wich the context is is wrapped by Context(), just remove it. Because Context() is deprecated.

    return t.render(Context(ctx))
    

    becomes

    return t.render(ctx)
    

提交回复
热议问题