Introduction
This is another article describing on how to solve an error message. The error message itself appear in the title of this article. Actually, there is a file with the name of ‘forms.py’. That file is a part of the Django-based application. It exist in the root of the application folder. It is a file for defining a specific form in order to display it in the Django template file. The following is the script which exist in that file :
from django import forms from .models import Organization class OrganizationForm(forms.ModelForm): class Meta: model = Organization fields = ('id')
In the middle of the execution of the Django internal service execution, the error appear as part of the output log. So, as in the Django internal service execution, the error exist appear as below :
(winenv) C:\django\project>python manage.py runserver Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). January 11, 2022 - 20:31:01 Django version 3.2.6, using settings 'core.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK. ... ... ... raise TypeError(msg) TypeError: OrganizationForm.Meta.fields cannot be a string. Did you mean to type: ('id',)?
Solution
So, the solution is very clear. There is a syntax error on the snippet code. There is an output log on the Django-based internal service execution. It is giving a suggestion to correct or to revise the source code. It is giving the suggestion to change the fields definition of the OrganizationForm class for the Meta function. So, the solution is to change as in the suggestion. So, just change the following line :
fields = ('id')
into the following revision :
fields = ('id',)
Overall, the following is the revision from the above source code :
from django import forms from .models import Organization class OrganizationForm(forms.ModelForm): class Meta: model = Organization fields = ('id',)
If there are no more errors appear, it shall give a proper response including the application which is running normal.