由于某种原因,这段代码导致我的许多模板出现ViewDoesNotExist
错误:
CHOICES = list ( (obj.manufacturer,obj.manufacturer) for obj in UniPart.objects.all().values('manufacturer').distinct() )
当我注释掉那段代码并用硬编码选择代替时,一切都很好。
发生了什么事?
以下是我在forms.py
中使用它的方法:
CHOICES = list ( (obj.manuacturer,obj.manufacturer) for obj in UniPart.objects.all().values('manufacturer').distinct() )
manufacturer = forms.ChoiceField(choices=CHOICES)
UniPart的定义如下:
class UniPart (models.Model):
manufacturer=models.CharField(_('manufacturer'), max_length=255)
这是urls.py
:
url(r'^add$','mysims.views.add_model'),
mysims
应用views.py
:
def add_model(request, points=None):
if request.method == "POST":
formtoaddmodel = newsimform(request.POST, request.FILES)
new_sim = formtoaddmodel.save(commit=False)