这是我的forms.py:
class stockupdateform(forms.ModelForm):
class Meta:
model:stock
fields =['categorie', 'nom', 'quantite'] 我的views.py:
def list_nom(request):
title='liste des produits'
form =stockSearchForm(request.POST or None)
queryset=stock.objects.all()
context= {
"title":title,
"queryset":queryset,
"form":form,
}
if request.method == 'POST':
queryset = stock.objects.filter(categorie=form['categorie'].value(),
nom=form['nom'].value())
context= {
"title":title,
"queryset":queryset,
"form":form,
}
return render(request, "list_nom.html",context) 我的list_nom.html:
<table class='table'>
<thead>
<tr>
<th>id</th>
<th>categorie</th>
<th>produit</th>
<th>quantite</th>
</tr>
</thead>
{% for instance in queryset %}
<tr>
<td>{{forloop.counter}}</td>
<td>{{instance.categorie}}</td>
<td><a href="{% url 'modifier_produit' instance.id %}">{{instance.nom}} </a> </td>
<td>{{instance.quantite}}</td>
</tr>
{% endfor %}
</table> 我有这个问题,我能做的是: ValueError at / ModelForm _ModelForm没有指定模型类。
发布于 2022-02-13 16:29:25
您不使用:设置变量,而是用=设置变量。假设stock是models中的一个类,则必须将stockupdateform更改为:
class stockupdateform(forms.ModelForm):
class Meta:
model = stock
fields = ['categorie', 'nom', 'quantite'] PS请与您的代码完全相同的缩进共享代码。以这种方式共享它是很重要的,因为我们可能认为您的缩进是不正确的(这段代码会下降100% )。
https://stackoverflow.com/questions/71102420
复制相似问题