![](/img/trans.png)
[英]UnboundLocalError local variable 'context' referenced before assignment
[英]UnboundLocalError at / local variable 'context' referenced before assignment
在我的 Django 應用程序中使用 views.py 出現此錯誤 - UnboundLocalError at / local variable 'context' referenced before assignment。
這是不工作的代碼片段:
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)
嘗試以下操作:
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.