无法在django中使用CreateView.as_视图
我是Django的新手,尝试使用CBV为我的“项目”模型生成表单。当我在url.py中使用CreateView.as_视图(…)时,会出现以下错误无法在django中使用CreateView.as_视图,django,django-forms,django-views,Django,Django Forms,Django Views,我是Django的新手,尝试使用CBV为我的“项目”模型生成表单。当我在url.py中使用CreateView.as_视图(…)时,会出现以下错误 Exception Type: ImproperlyConfigured Exception Value: Using ModelFormMixin (base class of CreateView) without the 'fields' attribute is prohibited. 我列出了与此视图相关的完整代码 url.
Exception Type: ImproperlyConfigured
Exception Value: Using ModelFormMixin (base class of CreateView) without the 'fields' attribute is prohibited.
我列出了与此视图相关的完整代码
url.py
url(r'^create-project/$', CreateView.as_view(model=Project,
template_name='en/public/create_project.html',
success_url='index'),
name='create_project')
class Form_project_create(forms.Form):
class Meta:
model = Project
fields = '__all__'
创建_project.py
url(r'^create-project/$', CreateView.as_view(model=Project,
template_name='en/public/create_project.html',
success_url='index'),
name='create_project')
class Form_project_create(forms.Form):
class Meta:
model = Project
fields = '__all__'
我想不出我们的代码出了什么问题。有人能帮忙吗?您还没有告诉CreateView使用该表单
url(r'^create-project/$', CreateView.as_view(form=Form_project_create, ...
另外请注意,表单本身需要继承自
forms.ModelForm
,而不是forms.form
form\u project\u create应该继承forms.ModelForm,而不是forms.form
class Form_project_create(forms.ModelForm):
class Meta:
model = Project
fields = '__all__'