Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 关于1.10中django.shortcuts.render()方法签名的混淆_Python_Django_Dictionary - Fatal编程技术网

Python 关于1.10中django.shortcuts.render()方法签名的混淆

Python 关于1.10中django.shortcuts.render()方法签名的混淆,python,django,dictionary,Python,Django,Dictionary,Django 1.10发行说明()说: 将删除以下函数的字典和上下文实例参数: django.shortcuts.render() 但是,1.10()中的render()文档仍然将context列为dictionary类型的参数: 上下文 要添加到模板上下文的值字典。默认情况下,这是一个空字典。如果字典中的值是可调用的,视图将在呈现模板之前调用它 坦率地说,我的问题是,什么给了你?通常这是一个学术问题,但以下代码: def index(request): context =

Django 1.10发行说明()说:

  • 将删除以下函数的字典和上下文实例参数:
    • django.shortcuts.render()
但是,1.10()中的
render()
文档仍然将
context
列为
dictionary
类型的参数:

上下文 要添加到模板上下文的值字典。默认情况下,这是一个空字典。如果字典中的值是可调用的,视图将在呈现模板之前调用它


坦率地说,我的问题是,什么给了你?通常这是一个学术问题,但以下代码:

def index(request):
    context = RequestContext(request, {})
    return render(request, 'maintenance/maintenance.html', context) 
产生以下错误:

TypeError: dict expected at most 1 arguments, got 3 

这是我能找到的关于问题所在的最好线索。我还应该提到,这个错误是在将Django从1.8更新到1.10之后出现的。

您混淆了
context
context\u instance
,这是两个独立的参数。Django 1.10中删除了
context\u实例
参数,但仍保留
context

正如文档所说,
context
应该是一个价值字典。出现错误是因为您传递的是
RequestContext
实例,而不是字典。您可以通过将示例视图更改为:

def index(request):
    context = {}
    return render(request, 'maintenance/maintenance.html', context)

前3个参数的签名未更改。一个名为
context\u instance
的可选关键字参数是被删除的。您能否(1.)提供完整的回溯,以及(2.)确保您的
render
实际上存在
django.shortcuts.render
?PS我认为它为您创建了一个
RequestContext
。您不需要在花括号内提供一些内容吗?