Skip to content
Advertisement

Specifying both ‘fields’ and ‘form_class’ is not permitted

I have the following form, which I want render it with Django crispy forms.

This is my views.py

JavaScript

This is my urls.py project main file :

JavaScript

This is my medical_encounter_information/urls.py

JavaScript

In my forms.py file I have:

JavaScript

The template medical_encounter_information/templates/medical_encounter_information/rehabilitationsession_form.html is:

JavaScript

When I type in my browser the url http://localhost:8000/sesiones-de-rehabilitacion/nuevo/ I get the following:

JavaScript

But, When I type in my browser the url http://localhost:8000/sesiones-de-rehabilitacion/editar/1 I view the following:

enter image description here

Because the view sesiones-de-rehabilitacion/editar/1 (RehabilitationSessionUpdate) is renderized, and the view sesiones-de-rehabilitacion/nuevo/ (RehabilitationSessionCreate) is not renderized knowing that together take the same template?

Advertisement

Answer

As the error says, you cannot set both form_class and fields for your view. You can either set form_class

JavaScript

Or you can set fields:

JavaScript

You shouldn’t need to set fields and form_class at the same time, because you can set fields on the form itself:

JavaScript
Advertisement