i正在尝试从表单Post获取数据。
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
我不是django
专家,但是如果您尝试更改此设置怎么办:
fields = (name,)
对此:
fields = ('name',)