简体   繁体   中英

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.

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) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM