簡體   English   中英

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

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM