Django:TypeError at/context必须是dict而不是tuple
执行此视图设置时,我不断收到错误消息:Django:TypeError at/context必须是dict而不是tuple,django,django-views,Django,Django Views,执行此视图设置时,我不断收到错误消息: from django.shortcuts import render # Create your views here. def home_screen_view(request): print(request.headers) return render(request, 'base.html', ()) 因此,我需要您的帮助尝试按照错误消息显示的信息进行操作。。。尝试将()替换为{}尝试按照错误消息显示的信息进行操作。。。尝试用{
from django.shortcuts import render
# Create your views here.
def home_screen_view(request):
print(request.headers)
return render(request, 'base.html', ())
因此,我需要您的帮助尝试按照错误消息显示的信息进行操作。。。尝试将()替换为{}尝试按照错误消息显示的信息进行操作。。。尝试用{}替换()正如错误所说,上下文应该是字典,而不是元组。对于空字典,使用大括号(
{}
),而不是括号(()
):
从django.shortcuts导入渲染
def home_screen_view(request):
print(request.headers)
return render(request, 'base.html', {})
# {} instead of () ^^
def主屏幕视图(请求):
打印(请求标题)
返回呈现(请求'base.html',{})
#{}上下文应该是字典,而不是元组,而不是错误所说的()^^
。对于空字典,使用大括号({}
),而不是括号(()
):
从django.shortcuts导入渲染
def home_screen_view(request):
print(request.headers)
return render(request, 'base.html', {})
# {} instead of () ^^
def主屏幕视图(请求):
打印(请求标题)
返回呈现(请求'base.html',{})
#{}而不是()^^