简体   繁体   English

UnboundLocalError at / local variable 'context' 在赋值之前引用

[英]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.

相关问题 分配前引用的 UnboundLocalError 局部变量“上下文” - UnboundLocalError local variable 'context' referenced before assignment 赋值前引用的 UnboundLocalError 局部变量 'context' Django - UnboundLocalError local variable 'context' referenced before assignment Django UnboundLocalError:分配前已引用局部变量“ truebomb” - UnboundLocalError: local variable 'truebomb' referenced before assignment UnboundLocalError:分配前已引用局部变量“ cur” - UnboundLocalError: local variable 'cur' referenced before assignment UnboundLocalError:分配前已引用局部变量“ Counter” - UnboundLocalError: local variable 'Counter' referenced before assignment UnBoundLocalError:赋值之前引用的局部变量(Python) - UnBoundLocalError: local variable referenced before assignment (Python) UnboundLocalError:分配前已引用局部变量“ strdate” - UnboundLocalError: local variable 'strdate' referenced before assignment UnboundLocalError:赋值之前引用了局部变量“ key” - UnboundLocalError: local variable 'key' referenced before assignment unboundLocalError:赋值前引用了局部变量“loopback” - unboundLocalError: local variable 'loopback' referenced before assignment UnboundLocalError:分配前已引用局部变量“ endProgram” - UnboundLocalError: local variable 'endProgram' referenced before assignment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM