1👍
Your view is not creating the form for get requests – how are you rendering the initial form?
If the form is not valid, print pessoaForm.errors
to see what the problem is. Print request.POST
to make sure the expected data is there. It looks like there’s a problem with the sobernome field, so check that especially closely.
0👍
I think the main problem here is the approach you’re using to implememt an “user profile”. See Storing additional information about users. You already are half way.
When you have configured the user profile correctly then you can associate the form to your profile class — Pessoa in this case –.
On the other hand, you are excluding usuario
and nome_completo
but the last is not a field of Pessoa
class.
Also, your Pessoa
class has fields which porpuse are the same of some User
model fields for instance: primeiro_nome
.
Recommendation:
- Visite the link I posted.
- Review you design, maybe you don’t want to define the field
primeiro_nome
in thePessoa
class. - Check that the data in
request.user.pessoa
is what your’re expecting for. Meaning thatprimeiro_nome
andsobrenome
fields have some data.
Finally in this answer — at last comment — you can see this OP was struggling with something like your problem.
He said: For the record I also tried user_form = UserForm(request.POST, instance=user, prefix='user')
: No error but that always returns an empty form.
Maybe you can try to load your form the way this answer propossed.
- [Answer]-Django – how to create duplicate apps without duplicating the code (models, signals and so on)
- [Answer]-Django Crispy form will not save/submit
- [Answer]-How do I put a background image on the body in css with django using static?
- [Answer]-Every 2nd and 3rd and 4th and 5th and so on