我得到“ModelForm没有指定模型类。” Django中的错误。我花了好几个小时来修复这个问题,但看不出问题所在。
非常感谢您提前!
回溯:
在get_response中输入文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/base.py”
111:response = wrapped_callback(request,* callback_args,** callback_kwargs) 在add_category中输入文件“/Users/LandonKoo/code/tango_with_django_project/rango/views.py”
71:form = CategoryForm() init 中的文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/forms/models.py”
312:引发ValueError('ModelForm没有指定模型类。')
异常类型:/ rango / add_category /
的ValueError
异常值:ModelForm没有指定模型类。
forms.py:
from django import forms
from rango.models import Page, Category
class CategoryForm(forms.ModelForm):
name = forms.CharField(max_length=128, help_text="Please enter the category name.")
views = forms.IntegerField(widget=forms.HiddenInput(), initial=0)
likes = forms.IntegerField(widget=forms.HiddenInput(), initial=0)
slug = forms.CharField(widget=forms.HiddenInput(), required=False)
print name, views, likes, slug
# An inline class to provide additional information on the form.
class Mata:
# Provide an association between the ModelForm and a model
model = Category
fields = ('name',)
views.py:
def add_category(request):
if request.method=="POST":
form = CategoryForm(request.POST)
if form.is_valid():
form.save(commit=True)
return index(request)
else:
print form.errors
else:
form = CategoryForm()
return render(request, 'rango/add_category.html', {'form': form})
答案 0 :(得分:2)
更改
pub fn f1(&mut self) {
let v = self.val;
println!("F1");
self.f2(v);
}
到
class Mata:
另外,我从未在模型中看到过print语句。拿出来以防万一。