28👍
You need to remove a white space at the end of 'body '
field, where you should have 'body'
like below:
class CommentForm(forms.ModelForm):
class Meta:
model = Comment
fields = ('name', 'email', 'body')
7👍
The same error also occurs if a model field with editable=False
is included in a form’s fields. Removing the editable
attribute on the model field fixes the error.
- [Django]-Best practice for Python & Django constants
- [Django]-How can I not use Django's admin login view?
- [Django]-Clean way to use postgresql window functions in django ORM?
3👍
I wasted a lot of time because I accidentally put a comma after the field definition in Model
- [Django]-Django JSONField inside ArrayField
- [Django]-Django Cache cache.set Not storing data
- [Django]-Django view – load template from calling app's dir first
2👍
if you don’t have any white space, then make "editable=TRUE" in models.py file.
for example:
class profile(models.Model):
username=models.CharField(max_length=200, blank=True, null=True, editable=True)
location=models.CharField(max_length=200, blank=True, null=True, editable=True)
name=models.CharField(max_length=200, blank=True, null=True, editable=True)
and then re-lunch your development server.
- [Django]-Django custom managers – how do I return only objects created by the logged-in user?
- [Django]-ManyRelatedManager not Iterable. Think I'm trying to pull my objects out incorrectly
- [Django]-How do I execute raw SQL in a django migration
1👍
remove the space in ‘body ‘
it will look like this
class CommentForm(forms.ModelForm):
class Meta:
model = Comment
fields = ('name', 'email', 'body')
- [Django]-What's the difference between Model.id and Model.pk in django?
- [Django]-How do I use prepared statements for inserting MULTIPLE records in SQlite using Python / Django?
- [Django]-How do I use Django groups and permissions?
1👍
I just had a variant of this problem where the spelling of the field name in the form was the same as in the model. And still I got the error.
I had declared the model field like this:
body = BooleanField(name="The comment's body text")
The mistake was to say name
where I wanted to say verbose_name
.
As a result, there was indeed no field called body
in the model, just like the error message claimed, rather the field was now called something much longer.
- [Django]-Access django models inside of Scrapy
- [Django]-How to query abstract-class-based objects in Django?
- [Django]-In a Django template for loop, checking if current item different from previous item