[Fixed]-Django.core.exceptions.ImproperlyConfigured

69👍

Like the error mentions, you need to explicitly specify the fields, or exclude.

Try this

class JobForm(models.ModelForm):
    #fields

    class Meta:
        model = Job
        fields = "__all__" 

which would include all the fields

Here is the relevant documentation (release notes 1.6)

Previously, if you wanted a ModelForm to use all fields on the model,
you could simply omit the Meta.fields attribute, and all fields would
be used.

This can lead to security problems where fields are added to the model
and, unintentionally, automatically become editable by end users. In
some cases, particular with boolean fields, it is possible for this
problem to be completely invisible. This is a form of Mass assignment
vulnerability.

For this reason, this behavior is deprecated, and using the
Meta.exclude option is strongly discouraged. Instead, all fields that
are intended for inclusion in the form should be listed explicitly in
the fields attribute.

If this security concern really does not apply in your case, there is
a shortcut to explicitly indicate that all fields should be used – use
the special value “__all__” for the fields attribute

5👍

You can set fields or exclude in the ModelForm in Django 1.7.
It changes in 1.8, you should set fields or exclude in the Meta class within ModelForm.

class JobForm(models.ModelForm):
#fields

class Meta:
    model = Job
    fields = "__all__" 

0👍

I got the same error when I set "Meta" inner class without "fields" or "exclude" attributes in "NewUserForm(UserCreationForm)" class in "account/forms.py" to create a form as shown below:

# "account/forms.py"

from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User

class NewUserForm(UserCreationForm):
  class Meta: # Here
    model = User

So, I added "fields" attribute to "Meta" inner class as shown below:

# "account/forms.py"

from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User

class NewUserForm(UserCreationForm):
  class Meta: # Here
    model = User
    fields = ("username",) # Here

Or, added "exclude" attribute to "Meta" inner class as shown below:

# "account/forms.py"

from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User

class NewUserForm(UserCreationForm):
  class Meta: # Here
    model = User
    exclude = ("first_name", "last_name") # Here

Then, I could solve the error.

-6👍

Dropping to Django 1.7 seemed to do the trick. There didn’t seem to be an easy way to adapt the code to fit Django 1.8.

👤Jon

Leave a comment