我试图从帖子中获取数据。
models.py
class Employee(models.Model):
name = models.CharField(max_length=100)
views.py
class Seller(CreateView):
fields = (name,)
model = models.Seller
def form_valid(self, form):
self.object = form.save(commit=False)
self.object.name = self.request.POST.get("name", "")+ "additional string" #concatenate string
self.object.save()
return super(ModelFormMixin, self).form_valid(form)
我的模板html
{{ form.as_p }}
来自cmd的错误
NameError: name 'name' is not defined
答案 0 :(得分:1)
我不是django
专家,但如果您尝试更改此内容,该怎么办:
fields = (name,)
到那个:
fields = ('name',)