[英]UnboundLocalError at / local variable 'context' referenced before assignment
Getting this error with views.py in my Django app - UnboundLocalError at / local variable 'context' referenced before assignment.在我的 Django 应用程序中使用 views.py 出现此错误 - UnboundLocalError at / local variable 'context' referenced before assignment。
Here is a snippet of the code that is not working:这是不工作的代码片段:
from django.shortcuts import render
from .models import *
def store(request):
products = Product.objects.all()
context: {'products':products}
return render(request, 'store/store.html', context)
Try the following:尝试以下操作:
from django.shortcuts import render
from .models import *
def store(request):
products = Product.objects.all()
context = {'products':products} #I have changed : to =
return render(request, 'store/store.html', context)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.